Compare commits
188
Commits
0.4.4
..
bcc2ffdc13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
26b9d6706d | ||
|
|
a21d4a9eb6 | ||
|
|
212d614ebd | ||
|
|
bcba3ccde0 | ||
|
|
b42ad76372 | ||
|
|
f95565771a | ||
|
|
3d6cbf5ac1 | ||
|
|
fc5d43e14b | ||
|
|
b3264748cd | ||
|
|
ede40f06d0 | ||
|
|
e69c675f82 | ||
|
|
17c1c90957 | ||
|
|
c6f2f71f6c | ||
|
|
d2c7c151bc | ||
|
|
4448eca787 | ||
|
|
0350a77dff | ||
|
|
4f98c599df | ||
|
|
103b2407d2 | ||
|
|
059da9be12 | ||
|
|
3cac3a997e | ||
|
|
3ffb001c73 | ||
|
|
2810a6f952 | ||
|
|
166362334b | ||
|
|
d3f9103ebf | ||
|
|
1c5507d4a5 | ||
|
|
5e3cd9f484 | ||
|
|
f27b884b6a | ||
|
|
769a9d8ea5 | ||
|
|
9499a7f0e0 | ||
|
|
ca38583f96 | ||
|
|
9557a0cfb5 | ||
|
|
c61e8bb7fc | ||
|
|
4fbcaa47f8 | ||
|
|
6f31fc5abb | ||
|
|
10ec0e35d0 | ||
|
|
29c4d253cf | ||
|
|
55c870d392 | ||
|
|
cda6ec066d | ||
|
|
c8b89e6847 | ||
|
|
b46a739008 | ||
|
|
af62394651 | ||
|
|
bc75a5cd97 | ||
|
|
7d8af3af08 | ||
|
|
ef8197b275 | ||
|
|
58d9ac7fdd | ||
|
|
86a893916d | ||
|
|
e7a6292fe9 | ||
|
|
81209b0cf8 | ||
|
|
77b8147f9b | ||
|
|
32abd7e14e | ||
|
|
8a582f0b08 | ||
|
|
01be6f7d43 | ||
|
|
9011700879 | ||
|
|
12cd4e5e5f | ||
|
|
10201bcadb | ||
|
|
3b4fcc0069 | ||
|
|
31a1ef74fb | ||
|
|
9be3a1475f | ||
|
|
7591f396fd | ||
|
|
517b84042f | ||
|
|
dbfae33074 | ||
|
|
ead34009c6 | ||
|
|
7a4a0f05d1 | ||
|
|
8f32b2d887 | ||
|
|
e6c9600b40 | ||
|
|
d5f2acb9ab | ||
|
|
3274e96355 | ||
|
|
78dfa286b0 | ||
|
|
f32624d131 | ||
|
|
59a417056c | ||
|
|
18f6704ed7 | ||
|
|
caf2f22e9f | ||
|
|
865966db55 | ||
|
|
6266a6293c | ||
|
|
70ea60aacf | ||
|
|
599cc44fff | ||
|
|
e1df59d512 | ||
|
|
eaa45976c7 | ||
|
|
362838c434 | ||
|
|
52caa9cdd2 | ||
|
|
c6afdb8762 | ||
|
|
c4964806f0 | ||
|
|
a2506b927a | ||
|
|
53061d9f78 | ||
|
|
2555dc7fc2 | ||
|
|
058087e15a | ||
|
|
c20c6393e5 | ||
|
|
a25ec85ba2 | ||
|
|
c930bda7a6 | ||
|
|
e7bc242292 | ||
|
|
b90a9ec7d8 | ||
|
|
d18a35d9b7 |
@@ -0,0 +1,32 @@
|
|||||||
|
name: Latest Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
jdk: [8, 11, 14, 16, 17, 18]
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up JDK ${{ matrix.jdk }}
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: ${{ matrix.jdk }}
|
||||||
|
|
||||||
|
- name: Validate Gradle wrapper
|
||||||
|
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
||||||
|
|
||||||
|
- name: Make gradlew executable
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew build
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
name: Unit Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
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
|
||||||
|
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
|
||||||
@@ -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
-2
@@ -1,7 +1,6 @@
|
|||||||
# ---> Gradle
|
# ---> Gradle
|
||||||
.gradle
|
.gradle
|
||||||
/build/
|
/build/
|
||||||
gradle.properties
|
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
@@ -31,5 +30,19 @@ gradle-app.setting
|
|||||||
/src/main/java/speiger/src/collections/doubles/*
|
/src/main/java/speiger/src/collections/doubles/*
|
||||||
/src/main/java/speiger/src/collections/objects/*
|
/src/main/java/speiger/src/collections/objects/*
|
||||||
|
|
||||||
|
#Generated Tests
|
||||||
|
/src/test/java/speiger/src/testers/booleans/*
|
||||||
|
/src/test/java/speiger/src/testers/bytes/*
|
||||||
|
/src/test/java/speiger/src/testers/shorts/*
|
||||||
|
/src/test/java/speiger/src/testers/chars/*
|
||||||
|
/src/test/java/speiger/src/testers/ints/*
|
||||||
|
/src/test/java/speiger/src/testers/longs/*
|
||||||
|
/src/test/java/speiger/src/testers/floats/*
|
||||||
|
/src/test/java/speiger/src/testers/doubles/*
|
||||||
|
/src/test/java/speiger/src/testers/objects/*
|
||||||
|
/src/test/java/speiger/src/tests/*
|
||||||
|
|
||||||
#Cache result
|
#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
|
||||||
|
|||||||
+263
-101
@@ -1,102 +1,264 @@
|
|||||||
# Changelog of versions
|
# Changelog of versions
|
||||||
|
|
||||||
### Version 0.4.4
|
### Version 0.8.0
|
||||||
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
- Added: getFirst/getLast/removeFirst/removeLast to Lists
|
||||||
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
- Added: Dedicated implementations for toArray into TreeSets
|
||||||
- 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.8.0
|
||||||
|
- Added: ISizeProvider interface (Optimization Helper)
|
||||||
### Version 0.4.3
|
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
|
||||||
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays.
|
||||||
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
- Added: Functions that have the same type, Int2IntFunction as example, have now a identity function.
|
||||||
|
- Added: Functions of a BooleanValue have now alwaysTrue/False function.
|
||||||
### Version 0.4.2
|
- Added: ForEachIndexed for all Iterable implementations
|
||||||
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
- Added: RandomGenerator support (Java17), though requires self compilation
|
||||||
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
- Added: Optimizations for HashUtils next power of function.
|
||||||
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
- Added: toArray() now returns a cached empty array if the collection is empty.
|
||||||
|
- Added: toArray function for AsyncBuilder
|
||||||
### Version 0.4.1
|
- Added: Modularization to the library where feature can be disabled as needed. (Requires Self-Compilation)
|
||||||
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
- Fixed: putIfAbsent now replaces defaultValues
|
||||||
- Added: addAll with Array-types in collections.
|
- Fixed: OpenHashSet/Map and their Custom Variants no longer rely on List implementations.
|
||||||
- Added: Java Iterator/Iterable support for Stream replacing methods
|
- Fixed: ObjectCopyOnWriteList.of did create a ObjectArrayList instead of the CopyOnWrite variant.
|
||||||
- Added: Suppliers.
|
- Removed: BooleanSet and Maps that start with a Boolean classes since they can not be used anyways.
|
||||||
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
|
- 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: Count feature into Iterable
|
- Breaking Change: Classes that used PrimitiveCollection functions now default to java functions where applicable, this is to increase compat.
|
||||||
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
|
- Breaking Change: Some function classes now get closer to javas terms. (Predicate/UnaryOperator etc)
|
||||||
|
|
||||||
### Version 0.4.0
|
### Version 0.7.0
|
||||||
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
- Added: Over 11 Million Unit Tests to this library to ensure quality.
|
||||||
- Added: New Stream replacing functions: findFirst, matchesAny/All/None
|
- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative
|
||||||
- Fixed: Compute/ComputeIfAbsent/ComputeIfPresent/Merge/BulkMerge in maps now behave like they should.
|
- Added: EnumMap specialized forEach implementation.
|
||||||
- Added: Implementations for New Stream replacing functions.
|
- Added: AbstractMap.remove now delegates to its primitive counterpart.
|
||||||
- Changed: Removed a lot of duplicated forEach implementations
|
- Added: ConcurrentHashMap now implements ITrimmable
|
||||||
- Added: Flat/Mapping functions (to object) are now accessible to primitive maps.
|
- Refactor: Removed a lot of disabled code from ArraySet.
|
||||||
- Added: Filter function to Iterators/Iterables (Iterable implements it by default)
|
- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required.
|
||||||
- Changed: Cleanup of some variables/mappers
|
- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly
|
||||||
- Added/Fixed: AVL/RBTreeMap got reworked and SubMaps work more properly now. Also forEach support got improved a lot
|
- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists.
|
||||||
- Added/Fixed: TreeSubSets (RB/AVL) got their functional implementations improved too.
|
- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists.
|
||||||
- Added: Pairs are now a thing. In Mutable/Immutable Form
|
- Fixed: AbstractList.Iterator.skip/back now keep track of the last returned value for remove function to work properly.
|
||||||
|
- Fixed: CopyOnWriteArrayList.extract/removeElements(int, int) does now proper range checks and remove elements properly.
|
||||||
### Version 0.3.6
|
- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely)
|
||||||
- Fixed: addAll non Type Specific Lists was causing crashes.
|
- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values.
|
||||||
- Fixed/Changed: clearAndTrim's implementation was all over the place. In some cases causing crash scenarios.
|
- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should.
|
||||||
- Fixed: Wrappers didn't implement toString/equals/hashCode
|
- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException.
|
||||||
- Added: Tests for addAll Bug
|
- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed.
|
||||||
- Changed: Cleaned up CodeStyle as bugs were fixed.
|
- Fixed: LinkedList.extractElement now returns the correct values.
|
||||||
|
- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed.
|
||||||
### Version 0.3.5
|
- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values.
|
||||||
- Fixed: Simple Code Generator dependency was declared wrong. Its only needed for runtime. Not for Compilation.
|
- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
- Fixed: ObjectLists Crashed when a null was provided as a Comparator. (Unless the List was Initialized with the ClassType)
|
- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
- Fixed: LinkedLists didn't implement add(Object)
|
- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
- Fixed: Object Collections did have the JavaCollections deprecated as the Constructor. This should only be deprecated for Primitives
|
- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
- Added: Tests with 5k Random names for Object sorting.
|
- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found.
|
||||||
- Changed: Object Arrays no longer require a Comparable[] it just assumes now that the elements in the Array are Comparable
|
- Fixed: Linked/EnumMap array constructor was creating the wrong size values array.
|
||||||
- Fixed: Dependency to SimpleCodeGenerator should be no longer a thing. Because the resulting library doesn't need it only the builder does.
|
- Fixed: LinkedEnumMap.getAndMoveToFirst/Last was moving elements even if the element wasn't present.
|
||||||
|
- Fixed: AVL/RBTreeMap.getFirst/LastKey was not throwing a NoSuchElementException if the map was empty.
|
||||||
### Version 0.3.4
|
- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder.
|
||||||
- Fixed: ArrayLists didn't resize properly if they were empty.
|
- Fixed: AVL/RBTreeSet.DecendingSet.subSet(from, fromInclusive, to, toInclusive) was creating a corrupt asending subset.
|
||||||
|
- 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.3.3
|
- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly.
|
||||||
- Added: Flat/Mapping function for Iterables/Iterators to help avoid streams for cleaner looking code
|
- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty.
|
||||||
- Fixed: AVLTrees pollFirst/Last is now keeping orders and is fixed
|
- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
- Fixed: AbstractCollection bulk adding methods now link to the specialized implementations.
|
- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
- 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.
|
### Version 0.6.2
|
||||||
- Added: Tests for LinkedList
|
- 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: Iterator Wrappers are now a bit more in Compliance with Java Standards.
|
||||||
### Version 0.3.2
|
- Added: AsyncBuilders now Support Array Inputs to create cleaner code.
|
||||||
- Fixed: Map.put wasn't referring to primitive variants.
|
- Changed: LinkedList.addBulk variable definition was triggering a false positive.
|
||||||
- Added: ImmutableList.
|
- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly.
|
||||||
- Added: Iterator pour function into a List or Array
|
- Fixed: SortedMap.sub/tail/headMap were looping into themselves.
|
||||||
- Changed: Arrays Wrap is now accessible to Objects and now is ? extends TYPE instead of TYPE.
|
- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer.
|
||||||
- Added: OpenHashSets now implement foreach and have less overhead.
|
- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection.
|
||||||
- Added: ImmutableOpenHashSet that is not editable (is linked by default for fast iteration)
|
- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes.
|
||||||
- Added: CustomOpenHashSets now implement foreach and have less overhead.
|
- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around.
|
||||||
- Added: ImmutableOpenHashMap that is not editable (is linked by default for fast iteration)
|
- Fixed: LinkedList.addElements(EmptyInput) would crash.
|
||||||
- Added: Maps can now be created through the interface.
|
- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one.
|
||||||
- Fixed: Lists.addElements(T...elements) was adding elements at the beginning of a list instead of the end.
|
- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed.
|
||||||
- Fixed: Bugs with the AVLTreeSet. And marked bugs with AVLTreeX that are still present.
|
- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place.
|
||||||
|
- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired.
|
||||||
### Version 0.3.1
|
- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value.
|
||||||
- Fixed: containsKey & containsValue in HashMaps were deprecated for Object Variants.
|
- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests.
|
||||||
- Fixed: HashMap wasn't deleting Keys & Values references when removing a Object
|
- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive.
|
||||||
- Fixed: AVLTreeMap didn't balance properly.
|
|
||||||
- Changed: EnumMap no longer tries to access SharedSecrets since its gone in java11
|
|
||||||
- Added: HashMaps now implement ITrimmable
|
### Version 0.6.1
|
||||||
- Added: AVLTreeSet didn't balance properly
|
- Fixed: FIFO queue crashing when the last index is before the first index when peek is called.
|
||||||
- Fixed: HashMaps & LinkedMaps weren't clearing references properly.
|
- Fixed: FIFO queue only clears the array if it was in use.
|
||||||
|
- Added: Sorted Method for the stream replacing functions.
|
||||||
### Version 0.3.0 (Breaking 0.2.0)
|
|
||||||
- Added: Stack.isEmpty was missing
|
### Version 0.6.0
|
||||||
- Changed: remove/removeLast/enqueue/enqueueFirst no longer use Type Suffixes
|
- Added: addOrGet for sets.
|
||||||
- Removed: Suffixes for unmodifiable & synchronize functions.
|
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
||||||
- Changed: Primitive Stacks no longer depend on the base Stack class. Because seriously not needed.
|
- Added: CopyOnWriteArrayList and tests for it
|
||||||
- Changed: PriorityQueues no longer extends Object Variant.
|
- Added: Support up to Java17.
|
||||||
- Changed: Maps.get function is no longer using Suffixes unless its absolutely necessary.
|
- Added: Build System now adds module-info if the Running JVM is 9 or higher
|
||||||
- Changed: Maps.remove function is no longer using Suffixes unless its absolutely necessary.
|
- 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.
|
||||||
- Changed: ObjectList methods are no longer marked Deprecated even so it was for primitive ones.
|
- Added: A ConcurrentHashMap implementation.
|
||||||
- Added: Shuffle & Reverse Methods.
|
- Fixed: containsValue in the HashMap wouldn't check the nullKey
|
||||||
- Added: Concat Iterators.
|
- Removed: Deprecated functions from SortedMaps/Sets
|
||||||
|
|
||||||
|
### Version 0.5.3
|
||||||
|
- Added: OrderedMap/Set
|
||||||
|
- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set
|
||||||
|
- Added: subFrom to Maps which is the counterpart of the addTo method
|
||||||
|
- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable
|
||||||
|
- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections.
|
||||||
|
- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted.
|
||||||
|
|
||||||
|
### Version 0.5.2
|
||||||
|
- Fixed: Bugs with Queues starting with the wrong size
|
||||||
|
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
|
||||||
|
- Added: Benchmarks with java and FastUtil
|
||||||
|
|
||||||
|
### Version 0.5.1
|
||||||
|
- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable.
|
||||||
|
- Added: Another 150k Unit tests.
|
||||||
|
- 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: Bugs with null values for primitive collections.
|
||||||
|
- Removed: ArraySet/Map subSet/subMap implementation was removed.
|
||||||
|
|
||||||
|
### Version 0.5.0
|
||||||
|
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||||
|
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
||||||
|
- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport)
|
||||||
|
- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before)
|
||||||
|
- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead.
|
||||||
|
- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing.
|
||||||
|
- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it)
|
||||||
|
- Added: A boxed putAll array variant.
|
||||||
|
- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date.
|
||||||
|
- Added: Tests for the new Stream replace functions to ensure no bugs are left.
|
||||||
|
- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys.
|
||||||
|
- Added: Guava TestSuit
|
||||||
|
- Fixed: HashCode and toString method would crash if the Object Key/Value was null
|
||||||
|
- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it.
|
||||||
|
- Fixed: Map.Entry toString wasn't writing values not like it should do.
|
||||||
|
- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements.
|
||||||
|
- Fixed: Added missing NonNull Checks.
|
||||||
|
- Fixed: Custom/OpenHashMap.containsValue implementation was wrong.
|
||||||
|
- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation
|
||||||
|
- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation
|
||||||
|
- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop.
|
||||||
|
- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry.
|
||||||
|
- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases.
|
||||||
|
- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue
|
||||||
|
- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present
|
||||||
|
- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps
|
||||||
|
- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps
|
||||||
|
- Fixed: SubLists are now properly implemented.
|
||||||
|
- Fixed: HashSet Iterator bugs now fixed... That was Painful.
|
||||||
|
- Added: Tests for Lists and Sets
|
||||||
|
|
||||||
|
### Version 0.4.5
|
||||||
|
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
||||||
|
- Fixed: Supplier get function wasn't referencing original function.
|
||||||
|
- Added: addIfPresent/Absent to lists
|
||||||
|
- Added: distinct, limit and peek iterators
|
||||||
|
- Added: Iterable's can now reduce its contents
|
||||||
|
- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created
|
||||||
|
- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted
|
||||||
|
- Added: More Test cases
|
||||||
|
|
||||||
|
### Version 0.4.4
|
||||||
|
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
||||||
|
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
||||||
|
- Added: Array/Collection version of enqueue and enqueueFirst to PriorityQueues.
|
||||||
|
- Added: fillBuffer function into PrimitiveLists which allow to optimize JavaNio buffers if needed.
|
||||||
|
|
||||||
|
### Version 0.4.3
|
||||||
|
- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance.
|
||||||
|
- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently.
|
||||||
|
|
||||||
|
### Version 0.4.2
|
||||||
|
- Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function.
|
||||||
|
Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function.
|
||||||
|
- Fixed: PriorityQueues didn't implement: hashCode/equals/toString
|
||||||
|
|
||||||
|
### Version 0.4.1
|
||||||
|
- Changed: ForEach with input now provides input, value instead of value, input, this improves the usage of method references greatly
|
||||||
|
- Added: addAll with Array-types in collections.
|
||||||
|
- Added: Java Iterator/Iterable support for Stream replacing methods
|
||||||
|
- Added: Suppliers.
|
||||||
|
- Added: SupplyIfAbsent. It is ComputeIfAbsent but using suppliers
|
||||||
|
- Added: Count feature into Iterable
|
||||||
|
- Fixed: A couple bugs with the new StreamReplacing functions in LinkedCollections Iterating to Infinity
|
||||||
|
|
||||||
|
### Version 0.4.0
|
||||||
|
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables
|
||||||
|
- 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
|
||||||
|
```
|
||||||
@@ -1,208 +1,201 @@
|
|||||||
Apache License
|
Apache License
|
||||||
|
Version 2.0, December 2021
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
Version 2.0, January 2021
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION,
|
|
||||||
AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and distribution
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
as defined by Sections 1 through 9 of this document.
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
owner that is granting the License.
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
"Object" form shall mean any form resulting from mechanical
|
||||||
that control, are controlled by, or are under common control with that entity.
|
transformation or translation of a Source form, including but
|
||||||
For the purposes of this definition, "control" means (i) the power, direct
|
not limited to compiled object code, generated documentation,
|
||||||
or indirect, to cause the direction or management of such entity, whether
|
and conversions to other media types.
|
||||||
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
|
|
||||||
of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
granted by this License.
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
but not limited to software source code, documentation source, and configuration
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
files.
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
or translation of a Source form, including but not limited to compiled object
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
code, generated documentation, and conversions to other media types.
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form,
|
(a) You must give any other recipients of the Work or
|
||||||
made available under the License, as indicated by a copyright notice that
|
Derivative Works a copy of this License; and
|
||||||
is included in or attached to the work (an example is provided in the Appendix
|
|
||||||
below).
|
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form,
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
that is based on (or derived from) the Work and for which the editorial revisions,
|
that You distribute, all copyright, patent, trademark, and
|
||||||
annotations, elaborations, or other modifications represent, as a whole, an
|
attribution notices from the Source form of the Work,
|
||||||
original work of authorship. For the purposes of this License, Derivative
|
excluding those notices that do not pertain to any part of
|
||||||
Works shall not include works that remain separable from, or merely link (or
|
the Derivative Works; and
|
||||||
bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version
|
You may add Your own copyright statement to Your modifications and
|
||||||
of the Work and any modifications or additions to that Work or Derivative
|
may provide additional or different license terms and conditions
|
||||||
Works thereof, that is intentionally submitted to Licensor for inclusion in
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
the Work by the copyright owner or by an individual or Legal Entity authorized
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
to submit on behalf of the copyright owner. For the purposes of this definition,
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
"submitted" means any form of electronic, verbal, or written communication
|
the conditions stated in this License.
|
||||||
sent to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems, and
|
|
||||||
issue tracking systems that are managed by, or on behalf of, the Licensor
|
|
||||||
for the purpose of discussing and improving the Work, but excluding communication
|
|
||||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
||||||
owner as "Not a Contribution."
|
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
of whom a Contribution has been received by Licensor and subsequently incorporated
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
within the Work.
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of this
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
Derivative Works of, publicly display, publicly perform, sublicense, and distribute
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
the Work and such Derivative Works in Source or Object form.
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
unless required by applicable law (such as deliberate and grossly
|
||||||
license to make, have made, use, offer to sell, sell, import, and otherwise
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
transfer the Work, where such license applies only to those patent claims
|
liable to You for damages, including any direct, indirect, special,
|
||||||
licensable by such Contributor that are necessarily infringed by their Contribution(s)
|
incidental, or consequential damages of any character arising as a
|
||||||
alone or by combination of their Contribution(s) with the Work to which such
|
result of this License or out of the use or inability to use the
|
||||||
Contribution(s) was submitted. If You institute patent litigation against
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
any entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
that the Work or a Contribution incorporated within the Work constitutes direct
|
other commercial damages or losses), even if such Contributor
|
||||||
or contributory patent infringement, then any patent licenses granted to You
|
has been advised of the possibility of such damages.
|
||||||
under this License for that Work shall terminate as of the date such litigation
|
|
||||||
is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the Work or
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
Derivative Works thereof in any medium, with or without modifications, and
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
in Source or Object form, provided that You meet the following conditions:
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or Derivative Works a copy
|
END OF TERMS AND CONDITIONS
|
||||||
of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices stating that
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works that You distribute,
|
To apply the Apache License to your work, attach the following
|
||||||
all copyright, patent, trademark, and attribution notices from the Source
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
form of the Work, excluding those notices that do not pertain to any part
|
replaced with your own identifying information. (Don't include
|
||||||
of the Derivative Works; and
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
Copyright 2021 Speiger
|
||||||
then any Derivative Works that You distribute must include a readable copy
|
|
||||||
of the attribution notices contained within such NOTICE file, excluding those
|
|
||||||
notices that do not pertain to any part of the Derivative Works, in at least
|
|
||||||
one of the following places: within a NOTICE text file distributed as part
|
|
||||||
of the Derivative Works; within the Source form or documentation, if provided
|
|
||||||
along with the Derivative Works; or, within a display generated by the Derivative
|
|
||||||
Works, if and wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and do not modify the
|
|
||||||
License. You may add Your own attribution notices within Derivative Works
|
|
||||||
that You distribute, alongside or as an addendum to the NOTICE text from the
|
|
||||||
Work, provided that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and may provide
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
additional or different license terms and conditions for use, reproduction,
|
you may not use this file except in compliance with the License.
|
||||||
or distribution of Your modifications, or for any such Derivative Works as
|
You may obtain a copy of the License at
|
||||||
a whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
||||||
complies with the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
||||||
Licensor shall be under the terms and conditions of this License, without
|
|
||||||
any additional terms or conditions. Notwithstanding the above, nothing herein
|
|
||||||
shall supersede or modify the terms of any separate license agreement you
|
|
||||||
may have executed with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names,
|
Unless required by applicable law or agreed to in writing, software
|
||||||
trademarks, service marks, or product names of the Licensor, except as required
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
for reasonable and customary use in describing the origin of the Work and
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
reproducing the content of the NOTICE file.
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
|
|
||||||
in writing, Licensor provides the Work (and each Contributor provides its
|
|
||||||
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
KIND, either express or implied, including, without limitation, any warranties
|
|
||||||
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness
|
|
||||||
of using or redistributing the Work and assume any risks associated with Your
|
|
||||||
exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory, whether
|
|
||||||
in tort (including negligence), contract, or otherwise, unless required by
|
|
||||||
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
||||||
in writing, shall any Contributor be liable to You for damages, including
|
|
||||||
any direct, indirect, special, incidental, or consequential damages of any
|
|
||||||
character arising as a result of this License or out of the use or inability
|
|
||||||
to use the Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all other commercial
|
|
||||||
damages or losses), even if such Contributor has been advised of the possibility
|
|
||||||
of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing the Work
|
|
||||||
or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
||||||
acceptance of support, warranty, indemnity, or other liability obligations
|
|
||||||
and/or rights consistent with this License. However, in accepting such obligations,
|
|
||||||
You may act only on Your own behalf and on Your sole responsibility, not on
|
|
||||||
behalf of any other Contributor, and only if You agree to indemnify, defend,
|
|
||||||
and hold each Contributor harmless for any liability incurred by, or claims
|
|
||||||
asserted against, such Contributor by reason of your accepting any such warranty
|
|
||||||
or additional liability. END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following boilerplate
|
|
||||||
notice, with the fields enclosed by brackets "[]" replaced with your own identifying
|
|
||||||
information. (Don't include the brackets!) The text should be enclosed in
|
|
||||||
the appropriate comment syntax for the file format. We also recommend that
|
|
||||||
a file or class name and description of purpose be included on the same "printed
|
|
||||||
page" as the copyright notice for easier identification within third-party
|
|
||||||
archives.
|
|
||||||
|
|
||||||
Copyright 2021 Speiger
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
|
|
||||||
limitations under the License.
|
|
||||||
|
|||||||
+2624
File diff suppressed because it is too large
Load Diff
@@ -1,93 +1,63 @@
|
|||||||
|

|
||||||
|
[](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
|
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||||
- HashSet/Map (Linked & HashControl)
|
- HashSets/Maps (Linked & HashControl)
|
||||||
- TreeSet/Map (RB & AVL)
|
- TreeSets/Maps (RB & AVL)
|
||||||
- EnumMap
|
- EnumMaps
|
||||||
- Immutable Maps/Lists/Sets
|
- Immutable Maps/Lists/Sets
|
||||||
- Priority Queue
|
- ConcurrentHashMaps
|
||||||
- Streams
|
- Priority Queues
|
||||||
- SplitIterators
|
- Streams & Functional Queries
|
||||||
- Iterators
|
- Split/Iterators
|
||||||
- Pairs
|
- Pairs
|
||||||
- Unary/Functions
|
- Unary/Functions
|
||||||
- Suppliers
|
- Suppliers
|
||||||
- Bi/Consumers
|
- Bi/Consumers
|
||||||
|
- AsyncBuilders
|
||||||
|
|
||||||
## 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
|
|
||||||
- Collection:
|
|
||||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
|
||||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
|
||||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
|
||||||
(subCollections/synchronized/unmodifiable not supported for obvious reasons)
|
|
||||||
- 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.
|
|
||||||
- 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)
|
|
||||||
- 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)
|
|
||||||
|
|
||||||
# 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.4.4'
|
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Direct:
|
|
||||||
|
|
||||||
| Version | Jar | Sources | Java Doc |
|
# SourceCode
|
||||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
The generated Sourcecode can be automatically build,
|
||||||
| 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) |
|
but if you want to just browse around in it.
|
||||||
| 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) |
|
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.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
|
||||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
|
||||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
|
||||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
|
||||||
| 0.3.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-javadoc.jar) |
|
|
||||||
| 0.3.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-javadoc.jar) |
|
|
||||||
| 0.3.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-javadoc.jar) |
|
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
If you want to contribute.
|
If you want to contribute.
|
||||||
@@ -105,12 +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)
|
|
||||||
- Testing for Sub Maps/Sets/Lists are only in a very basic way tested
|
|
||||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
|
||||||
|
|||||||
+216
-22
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
id "jacoco"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
@@ -8,7 +9,7 @@ tasks.withType(JavaCompile) {
|
|||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -18,9 +19,11 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.4.4';
|
version = '0.8.0';
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||||
|
|
||||||
|
System.out.println("Java Version: "+compileJava.sourceCompatibility)
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
options.tags = [ "implSpec", "note" ]
|
options.tags = [ "implSpec", "note" ]
|
||||||
@@ -42,9 +45,11 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
builderCompile 'de.speiger:Simple-Code-Generator:1.0.5'
|
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||||
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5'
|
builderImplementation 'de.speiger:Simple-Code-Generator:1.2.2'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
|
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateSource(type: JavaExec) {
|
task generateSource(type: JavaExec) {
|
||||||
@@ -54,12 +59,36 @@ task generateSource(type: JavaExec) {
|
|||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task generateGithubSource(type: JavaExec) {
|
||||||
|
group = 'internal'
|
||||||
|
description = 'Builds the sourcecode for Github Actions'
|
||||||
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
|
args = ['silent']
|
||||||
|
}
|
||||||
|
|
||||||
task forceGenerateSource(type: JavaExec) {
|
task forceGenerateSource(type: JavaExec) {
|
||||||
group = 'internal'
|
group = 'internal'
|
||||||
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 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) {
|
||||||
@@ -72,6 +101,8 @@ task srcJar(type: Jar) {
|
|||||||
classifier = 'sources'
|
classifier = '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()
|
||||||
@@ -81,23 +112,171 @@ artifacts {
|
|||||||
archives srcJar
|
archives srcJar
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
task testBooleans(type: Test) {
|
||||||
useJUnit()
|
group 'tests'
|
||||||
|
description 'Tests all Boolean Collections'
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
includeTestsMatching "speiger.src.tests.booleans.**.*"
|
||||||
|
}
|
||||||
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadArchives {
|
task testBytes(type: Test) {
|
||||||
repositories.mavenDeployer {
|
group 'tests'
|
||||||
repository(url: 'https://maven.speiger.com/repository/main') {
|
description 'Tests all Byte Collections'
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
filter {
|
||||||
}
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
includeTestsMatching "speiger.src.tests.bytes.**.*"
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
}
|
||||||
}
|
useJUnit()
|
||||||
pom {
|
ignoreFailures = true
|
||||||
version = project.version
|
maxHeapSize = "1024m"
|
||||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
maxParallelForks = 2
|
||||||
groupId = 'de.speiger'
|
}
|
||||||
project {
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
excludeTestsMatching "speiger.src.tests.**.*"
|
||||||
|
excludeTestsMatching "tests.**.*"
|
||||||
|
}
|
||||||
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
|
}
|
||||||
|
|
||||||
|
jacocoTestReport {
|
||||||
|
executionData fileTree(project.buildDir.absolutePath).include("jacoco/*.exec")
|
||||||
|
reports {
|
||||||
|
xml.enabled true
|
||||||
|
html.enabled = true
|
||||||
|
csv.enabled true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
Properties props = new Properties()
|
||||||
|
if(file("$buildDir/credentials.properties").exists()) {
|
||||||
|
props.load(new FileInputStream("$buildDir/credentials.properties"))
|
||||||
|
}
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
pom {
|
||||||
|
name = 'Primitive Collections'
|
||||||
|
description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||||
|
version = project.version
|
||||||
|
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||||
|
groupId = 'de.speiger'
|
||||||
|
from components.java
|
||||||
|
artifact tasks.srcJar
|
||||||
|
artifact tasks.javadocJar
|
||||||
licenses {
|
licenses {
|
||||||
license {
|
license {
|
||||||
name = 'The Apache License, Version 2.0'
|
name = 'The Apache License, Version 2.0'
|
||||||
@@ -108,9 +287,24 @@ uploadArchives {
|
|||||||
developer {
|
developer {
|
||||||
id = 'speiger'
|
id = 'speiger'
|
||||||
name = 'Speiger'
|
name = 'Speiger'
|
||||||
email = 'speiger@gmx.net'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scm {
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||||
|
}
|
||||||
|
issueManagement {
|
||||||
|
system = 'github'
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main"
|
||||||
|
credentials(PasswordCredentials) {
|
||||||
|
username props.mavenUser
|
||||||
|
password props.mavenPassword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+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>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx3G
|
||||||
+1
-1
@@ -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-6.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
jdk:
|
||||||
|
- openjdk9
|
||||||
|
install:
|
||||||
|
- chmod +x ./gradlew
|
||||||
|
- ./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,440 +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("<>");
|
|
||||||
|
|
||||||
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() ? "%s.hashCode()" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
|
||||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "%s.toString()" : type.getClassType(value)+".toString(%s)").removeBraces();
|
|
||||||
|
|
||||||
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
|
||||||
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
|
||||||
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");
|
|
||||||
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("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");
|
|
||||||
|
|
||||||
//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("SORTED_MAP", "SortedMap", "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("SET", "Set");
|
|
||||||
addClassMapper("STRATEGY", "Strategy");
|
|
||||||
addClassMapper("STACK", "Stack");
|
|
||||||
addClassMapper("SUPPLIER", "Supplier");
|
|
||||||
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_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");
|
|
||||||
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,180 +1,270 @@
|
|||||||
package speiger.src.builder;
|
package speiger.src.builder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.BufferedWriter;
|
||||||
import java.nio.file.Path;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.nio.file.Path;
|
||||||
import java.util.EnumSet;
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.HashSet;
|
||||||
import java.util.function.Consumer;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import speiger.src.builder.processor.TemplateProcess;
|
import java.util.Set;
|
||||||
import speiger.src.builder.processor.TemplateProcessor;
|
import java.util.StringJoiner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
@SuppressWarnings("javadoc")
|
import java.util.stream.Stream;
|
||||||
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|
||||||
{
|
import speiger.src.builder.modules.AsyncModule;
|
||||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
import speiger.src.builder.modules.BaseModule;
|
||||||
Map<String, String> nameRemapper = new HashMap<>();
|
import speiger.src.builder.modules.CollectionModule;
|
||||||
Map<String, String> biRequired = new HashMap<>();
|
import speiger.src.builder.modules.FunctionModule;
|
||||||
Set<String> enumRequired = new HashSet<>();
|
import speiger.src.builder.modules.JavaModule;
|
||||||
public static final ClassType[] TYPE = ClassType.values();
|
import speiger.src.builder.modules.ListModule;
|
||||||
List<GlobalVariables> variables = new ArrayList<>();
|
import speiger.src.builder.modules.MapModule;
|
||||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
import speiger.src.builder.modules.PairModule;
|
||||||
List<GlobalVariables> enumVariables = new ArrayList<>();
|
import speiger.src.builder.modules.PrioQueueModule;
|
||||||
|
import speiger.src.builder.modules.SetModule;
|
||||||
public PrimitiveCollectionsBuilder()
|
import speiger.src.builder.processor.TemplateProcess;
|
||||||
{
|
import speiger.src.builder.processor.TemplateProcessor;
|
||||||
super(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/"));
|
|
||||||
}
|
@SuppressWarnings("javadoc")
|
||||||
|
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||||
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
{
|
||||||
{
|
private static final int SPECIAL = 0x1; //Detects if the Builder is generating tests
|
||||||
super(sourceFolder, outputFolder, dataFolder);
|
private static final int LOAD = 0x2; //If Configs should be loaded
|
||||||
}
|
private static final int ANTI_SAVE = SPECIAL | LOAD; //If save should be disabled since load/save shouldn't happen at the same time.
|
||||||
|
private static final int SAVE = 0x4; //if the configuration should be created
|
||||||
@Override
|
Set<String> globalFlags = new HashSet<>();
|
||||||
protected boolean isFileValid(Path fileName)
|
List<ModulePackage> simplePackages = new ArrayList<>();
|
||||||
{
|
List<ModulePackage> biPackages = new ArrayList<>();
|
||||||
return true;
|
List<ModulePackage> enumPackages = new ArrayList<>();
|
||||||
}
|
Map<String, RequiredType> requirements = new HashMap<>();
|
||||||
|
SettingsManager manager = new SettingsManager();
|
||||||
@Override
|
int flags;
|
||||||
protected boolean relativePackages()
|
|
||||||
{
|
public PrimitiveCollectionsBuilder()
|
||||||
return true;
|
{
|
||||||
}
|
this(false);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
protected boolean debugUnusedMappers()
|
public PrimitiveCollectionsBuilder(boolean silencedSuccess)
|
||||||
{
|
{
|
||||||
return false;
|
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
|
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||||
protected void init()
|
{
|
||||||
{
|
this(false, sourceFolder, outputFolder, dataFolder);
|
||||||
variables.clear();
|
}
|
||||||
for(ClassType clzType : TYPE)
|
|
||||||
{
|
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||||
for(ClassType subType : TYPE)
|
{
|
||||||
{
|
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||||
create(clzType, subType);
|
}
|
||||||
}
|
|
||||||
}
|
private PrimitiveCollectionsBuilder setFlags(int flags) {
|
||||||
enumRequired.add("EnumMap");
|
this.flags = flags;
|
||||||
enumRequired.add("LinkedEnumMap");
|
if((flags & ANTI_SAVE) != 0) {
|
||||||
biRequired.put("BiConsumer", "");
|
this.flags &= ~SAVE;
|
||||||
biRequired.put("UnaryOperator", "");
|
}
|
||||||
biRequired.put("Pair", "");
|
return this;
|
||||||
biRequired.put("MutablePair", "");
|
}
|
||||||
biRequired.put("ImmutablePair", "");
|
|
||||||
addBiClass("Function", "Maps", "Map", "SortedMap", "NavigableMap", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
private static PrimitiveCollectionsBuilder createTests(boolean silent, int flags) {
|
||||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
nameRemapper.put("IArray", "I%sArray");
|
Paths.get("src/builder/resources/speiger/assets/tests/templates/"),
|
||||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
Paths.get("src/test/java/speiger/src/tests/"),
|
||||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
Paths.get("src/builder/resources/speiger/assets/tests/")).setFlags(flags | SPECIAL);
|
||||||
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
}
|
||||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
|
||||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
private static PrimitiveCollectionsBuilder createTesters(boolean silent, int flags) {
|
||||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
Paths.get("src/builder/resources/speiger/assets/testers/templates/"),
|
||||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
Paths.get("src/test/java/speiger/src/testers/"),
|
||||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
Paths.get("src/builder/resources/speiger/assets/testers/")).setFlags(flags | SPECIAL);
|
||||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
}
|
||||||
|
|
||||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
@Override
|
||||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
protected boolean isFileValid(Path fileName)
|
||||||
addBlockage(ClassType.BOOLEAN, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
{
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
protected void create(ClassType mainType, ClassType subType)
|
|
||||||
{
|
@Override
|
||||||
GlobalVariables type = new GlobalVariables(mainType, subType);
|
protected boolean relativePackages()
|
||||||
type.createFlags();
|
{
|
||||||
type.createHelperVariables();
|
return true;
|
||||||
type.createVariables();
|
}
|
||||||
type.createPreFunctions();
|
|
||||||
type.createClassTypes();
|
@Override
|
||||||
type.createFunctions();
|
protected boolean debugUnusedMappers()
|
||||||
if(mainType == subType) variables.add(type);
|
{
|
||||||
biVariables.add(type);
|
return false;
|
||||||
if(mainType.isObject()) enumVariables.add(type);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
protected void addBiClass(String...classNames)
|
protected void afterFinish()
|
||||||
{
|
{
|
||||||
for(String s : classNames)
|
if((flags & SPECIAL) == 0 && getVersion() > 8)
|
||||||
{
|
{
|
||||||
biRequired.put(s, "2");
|
Path basePath = Paths.get("src/main/java");
|
||||||
}
|
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
||||||
}
|
{
|
||||||
|
writer.write(getModuleInfo(basePath));
|
||||||
protected void addBlockage(ClassType type, String...args)
|
}
|
||||||
{
|
catch(Exception e)
|
||||||
for(String s : args)
|
{
|
||||||
{
|
e.printStackTrace();
|
||||||
EnumSet<ClassType> set = blocked.get(s);
|
}
|
||||||
if(set == null)
|
}
|
||||||
{
|
}
|
||||||
set = EnumSet.noneOf(ClassType.class);
|
|
||||||
blocked.put(s, set);
|
public List<BaseModule> createModules()
|
||||||
}
|
{
|
||||||
set.add(type);
|
List<BaseModule> modules = new ArrayList<>();
|
||||||
}
|
modules.add(JavaModule.INSTANCE);
|
||||||
}
|
modules.add(FunctionModule.INSTANCE);
|
||||||
|
modules.add(CollectionModule.INSTANCE);
|
||||||
@Override
|
modules.add(PrioQueueModule.INSTANCE);
|
||||||
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
|
modules.add(ListModule.INSTANCE);
|
||||||
{
|
modules.add(SetModule.INSTANCE);
|
||||||
String splitter = biRequired.get(name);
|
modules.add(MapModule.INSTANCE);
|
||||||
boolean valueRequired = enumRequired.contains(name);
|
modules.add(PairModule.INSTANCE);
|
||||||
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
modules.add(AsyncModule.INSTANCE);
|
||||||
EnumSet<ClassType> types = blocked.get(name);
|
return modules;
|
||||||
for(int i = 0,m=vars.size();i<m;i++)
|
}
|
||||||
{
|
|
||||||
GlobalVariables type = vars.get(i);
|
|
||||||
if(types == null || !types.contains(type.getType()))
|
@Override
|
||||||
{
|
protected void init()
|
||||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
{
|
||||||
}
|
prepPackages();
|
||||||
}
|
//Init Modules here
|
||||||
}
|
addModules(createModules());
|
||||||
|
finishPackages();
|
||||||
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
}
|
||||||
if(enumRequired.contains(name)) return enumVariables;
|
|
||||||
if(bi) return biVariables;
|
public void addModules(List<BaseModule> modules)
|
||||||
return variables;
|
{
|
||||||
}
|
for(int i = 0,m=modules.size();i<m;i++) {
|
||||||
|
modules.get(i).setManager(manager);
|
||||||
public static void main(String...args)
|
}
|
||||||
{
|
for(int i = 0,m=modules.size();i<m;i++) {
|
||||||
try
|
biPackages.forEach(modules.get(i)::init);
|
||||||
{
|
}
|
||||||
if(args.length == 0) {
|
for(int i = 0,m=modules.size();i<m;i++) {
|
||||||
new PrimitiveCollectionsBuilder().process(false);
|
modules.get(i).cleanup();
|
||||||
} else if(args.length == 1) {
|
}
|
||||||
new PrimitiveCollectionsBuilder().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);
|
private void finishPackages()
|
||||||
} else if(args.length == 4) {
|
{
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
biPackages.forEach(ModulePackage::finish);
|
||||||
} else {
|
if((flags & SAVE) != 0) manager.save();
|
||||||
System.out.println("Invalid argument count passed in");
|
}
|
||||||
System.exit(1);
|
|
||||||
}
|
private void prepPackages()
|
||||||
}
|
{
|
||||||
catch(InterruptedException e)
|
if((flags & LOAD) != 0) manager.load();
|
||||||
{
|
for(ModulePackage entry : ModulePackage.createPackages(globalFlags))
|
||||||
e.printStackTrace();
|
{
|
||||||
}
|
entry.setRequirements(requirements::put);
|
||||||
catch(IOException e)
|
biPackages.add(entry);
|
||||||
{
|
if(entry.isSame()) simplePackages.add(entry);
|
||||||
e.printStackTrace();
|
if(entry.isEnumValid()) enumPackages.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
|
||||||
|
{
|
||||||
|
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
|
||||||
|
for(int i = 0,m=packages.size();i<m;i++)
|
||||||
|
{
|
||||||
|
packages.get(i).process(fileName, process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
|
||||||
|
if(type == null) return simplePackages;
|
||||||
|
if(type == RequiredType.BI_CLASS) return biPackages;
|
||||||
|
if(type == RequiredType.ENUM) return enumPackages;
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getModuleInfo(Path basePath) {
|
||||||
|
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
||||||
|
try(Stream<Path> stream = Files.walk(getOutputFolder()))
|
||||||
|
{
|
||||||
|
stream.filter(Files::isDirectory)
|
||||||
|
.filter(this::containsFiles)
|
||||||
|
.map(basePath::relativize)
|
||||||
|
.map(Path::toString)
|
||||||
|
.map(this::sanitize)
|
||||||
|
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("/** @author Speiger */\n");
|
||||||
|
builder.append("module ").append(sanitize(basePath.relativize(getOutputFolder()).toString())).append(" {\n");
|
||||||
|
builder.append(joiner.toString()).append("}");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String sanitize(String input)
|
||||||
|
{
|
||||||
|
return input.replace("\\", ".").replace("/", ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsFiles(Path path)
|
||||||
|
{
|
||||||
|
try(Stream<Path> stream = Files.walk(path, 1))
|
||||||
|
{
|
||||||
|
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getVersion()
|
||||||
|
{
|
||||||
|
String version = System.getProperty("java.version");
|
||||||
|
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||||
|
int dot = version.indexOf(".");
|
||||||
|
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String...args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Set<String> flags = new HashSet<>(Arrays.asList(args));
|
||||||
|
boolean silent = flags.contains("silent");
|
||||||
|
boolean force = flags.contains("force");
|
||||||
|
boolean tests = flags.contains("tests");
|
||||||
|
boolean forceTests = flags.contains("force-tests");
|
||||||
|
boolean load = flags.contains("load");
|
||||||
|
boolean save = flags.contains("save");
|
||||||
|
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
|
||||||
|
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);
|
||||||
|
if(tests) {
|
||||||
|
createTests(silent, flag).process(force || forceTests);
|
||||||
|
createTesters(silent, flag).process(force || forceTests);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(InterruptedException | IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package speiger.src.builder;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public enum RequiredType
|
||||||
|
{
|
||||||
|
BI_CLASS,
|
||||||
|
ENUM
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package speiger.src.builder;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
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.modules.BaseModule;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SettingsManager
|
||||||
|
{
|
||||||
|
boolean loaded;
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
|
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType) {
|
||||||
|
if(!loaded) return true;
|
||||||
|
if(!isEnabled(data, base.getModuleName())) return false;
|
||||||
|
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||||
|
if(!isEnabled(result, "Enabled")) return false;
|
||||||
|
if(base.isBiModule()) {
|
||||||
|
result = getObject(result, valueType.getClassPath(), false);
|
||||||
|
if(!isEnabled(result, "Enabled")) return false;
|
||||||
|
}
|
||||||
|
result = getObject(result, base.getModuleName(), false);
|
||||||
|
return (result.size() <= 0 || isEnabled(result, "Enabled")) && base.areDependenciesLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType, String entry)
|
||||||
|
{
|
||||||
|
if(!loaded) return true;
|
||||||
|
if(!isEnabled(data, base.getModuleName())) return false;
|
||||||
|
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||||
|
if(!isEnabled(result, "Enabled")) return false;
|
||||||
|
if(base.isBiModule()) {
|
||||||
|
result = getObject(result, valueType.getClassPath(), false);
|
||||||
|
if(!isEnabled(result, "Enabled")) return false;
|
||||||
|
}
|
||||||
|
result = getObject(result, base.getModuleName(), false);
|
||||||
|
return (result.size() <= 0 || (isEnabled(result, "Enabled") && isEnabled(result, entry))) && base.areDependenciesLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addModule(BaseModule module) {
|
||||||
|
if(loaded) 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();
|
||||||
|
obj.addProperty("Enabled", true);
|
||||||
|
for(String key : module.getModuleKeys(keyType, valueType)) {
|
||||||
|
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();
|
||||||
|
obj.addProperty("Enabled", true);
|
||||||
|
for(String key : module.getModuleKeys(keyType, keyType)) {
|
||||||
|
obj.addProperty(key, true);
|
||||||
|
}
|
||||||
|
addModule(keyType, keyType, false, moduleName, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
|
||||||
|
data = JsonParser.parseReader(reader).getAsJsonObject();
|
||||||
|
loaded = true;
|
||||||
|
}
|
||||||
|
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(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEnabled(JsonObject obj, String key) {
|
||||||
|
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class AsyncModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new AsyncModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Async"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers() {}
|
||||||
|
@Override
|
||||||
|
protected void loadTestClasses() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions() {}
|
||||||
|
@Override
|
||||||
|
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades() {
|
||||||
|
if(!isModuleEnabled()) {
|
||||||
|
addBlockedFiles("AsyncBuilder", "Task");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {
|
||||||
|
if(isModuleEnabled()) {
|
||||||
|
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,205 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
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.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();
|
||||||
|
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 Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
|
||||||
|
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }
|
||||||
|
|
||||||
|
protected boolean isModuleEnabled() {
|
||||||
|
return manager == null || manager.isModuleEnabled(this, keyType, valueType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isModuleEnabled(String name) {
|
||||||
|
return manager == null || manager.isModuleEnabled(this, keyType, valueType, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isDependencyLoaded(BaseModule module) {
|
||||||
|
return isDependencyLoaded(module, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isDependencyLoaded(BaseModule module, boolean key) {
|
||||||
|
return manager == null || (module.isBiModule() ? manager.isModuleEnabled(module, keyType, valueType) : (key ? manager.isModuleEnabled(module, keyType, keyType) : manager.isModuleEnabled(module, valueType, valueType)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean areDependenciesLoaded() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class CollectionModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new CollectionModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Collection"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
public boolean areDependenciesLoaded(){ return isDependencyLoaded(JavaModule.INSTANCE); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType)
|
||||||
|
{
|
||||||
|
return new TreeSet<>(Arrays.asList("Streams", "Splititerators", "IArray", "Strategy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {
|
||||||
|
if(isModuleEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||||
|
if(isModuleEnabled("Streams")) addKeyFlag("STREAM_FEATURE");
|
||||||
|
if(isModuleEnabled("Splititerators")) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||||
|
if(isModuleEnabled("IArray")) addKeyFlag("IARRAY_FEATURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades() {
|
||||||
|
if(!isModuleEnabled()) {
|
||||||
|
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
|
||||||
|
addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack");
|
||||||
|
}
|
||||||
|
if(!isModuleEnabled("Splititerators")) addBlockedFiles("Splititerator", "Splititerators");
|
||||||
|
if(!isModuleEnabled("IArray")) addBlockedFiles("IArray");
|
||||||
|
if(!isModuleEnabled("Strategy")) addBlockedFiles("Strategy");
|
||||||
|
|
||||||
|
if(keyType.isObject()) {
|
||||||
|
addBlockedFiles("Stack");
|
||||||
|
addBlockedFiles("CollectionStreamTester");
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
|
||||||
|
//Helper Classes
|
||||||
|
addClassMapper("ARRAYS", "Arrays");
|
||||||
|
addClassMapper("COLLECTIONS", "Collections");
|
||||||
|
addClassMapper("ITERABLES", "Iterables");
|
||||||
|
addClassMapper("SPLIT_ITERATORS", "Splititerators");
|
||||||
|
addClassMapper("ITERATORS", "Iterators");
|
||||||
|
|
||||||
|
//Interfaces
|
||||||
|
addClassMapper("COLLECTION", "Collection");
|
||||||
|
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,107 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
import speiger.src.builder.RequiredType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class FunctionModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new FunctionModule();
|
||||||
|
|
||||||
|
@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
|
||||||
|
protected void loadBlockades()
|
||||||
|
{
|
||||||
|
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions()
|
||||||
|
{
|
||||||
|
addSimpleMapper("APPLY", keyType.getApply(valueType));
|
||||||
|
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
|
||||||
|
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getCustomJDKType().getNonFileType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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");
|
||||||
|
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,221 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class JavaModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new JavaModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Base"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables()
|
||||||
|
{
|
||||||
|
createHelperVars(keyType, false, "KEY");
|
||||||
|
createHelperVars(valueType, true, "VALUE");
|
||||||
|
loadBaseVariables();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
|
||||||
|
//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");
|
||||||
|
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,118 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ListModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new ListModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "List"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {
|
||||||
|
if(isModuleEnabled()) addKeyFlag("LIST_MODULE");
|
||||||
|
if(isModuleEnabled("Wrappers")) addKeyFlag("LISTS_FEATURE");
|
||||||
|
boolean implementations = isModuleEnabled("Implementations");
|
||||||
|
if(implementations && isModuleEnabled("ArrayList")) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("LinkedList")) addKeyFlag("LINKED_LIST_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("ImmutableList")) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("CopyOnWriteList")) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades()
|
||||||
|
{
|
||||||
|
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Lists");
|
||||||
|
boolean implementations = !isModuleEnabled("Implementations");
|
||||||
|
if(implementations || !isModuleEnabled("ArrayList")) addBlockedFiles("ArrayList");
|
||||||
|
if(implementations || !isModuleEnabled("LinkedList")) addBlockedFiles("LinkedList");
|
||||||
|
if(implementations || !isModuleEnabled("ImmutableList")) addBlockedFiles("ImmutableList");
|
||||||
|
if(implementations || !isModuleEnabled("CopyOnWriteList")) addBlockedFiles("CopyOnWriteList");
|
||||||
|
if(!isModuleEnabled()) addBlockedFiles("List", "AbstractList");
|
||||||
|
|
||||||
|
if(keyType.isObject()) addBlockedFiles("ListFillBufferTester");
|
||||||
|
if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||||
|
return new TreeSet<>(Arrays.asList("Implementations", "Wrappers", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areDependenciesLoaded() {
|
||||||
|
return isDependencyLoaded(CollectionModule.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,281 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class MapModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new MapModule();
|
||||||
|
|
||||||
|
@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 boolean areDependenciesLoaded() { return isDependencyLoaded(SetModule.INSTANCE) && isDependencyLoaded(CollectionModule.INSTANCE, false); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||||
|
Set<String> sets = new TreeSet<>();
|
||||||
|
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||||
|
sets.addAll(Arrays.asList("OrderedMap", "SortedMap"));
|
||||||
|
sets.addAll(Arrays.asList("ArrayMap", "ConcurrentMap", "ImmutableMap"));
|
||||||
|
sets.addAll(Arrays.asList("HashMap", "LinkedHashMap"));
|
||||||
|
sets.addAll(Arrays.asList("CustomHashMap", "LinkedCustomHashMap"));
|
||||||
|
sets.addAll(Arrays.asList("EnumMap", "LinkedEnumMap"));
|
||||||
|
sets.addAll(Arrays.asList("AVLTreeMap", "RBTreeMap"));
|
||||||
|
return sets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags()
|
||||||
|
{
|
||||||
|
if(isModuleEnabled()) addFlag("MAP_MODULE");
|
||||||
|
if(isModuleEnabled("Wrappers")) addFlag("MAPS_FEATURE");
|
||||||
|
boolean implementations = isModuleEnabled("Implementations");
|
||||||
|
boolean hashMap = implementations && isModuleEnabled("HashMap");
|
||||||
|
boolean customHashMap = implementations && isModuleEnabled("CustomHashMap");
|
||||||
|
boolean enumMap = implementations && isModuleEnabled("EnumMap");
|
||||||
|
|
||||||
|
if(isModuleEnabled("OrderedMap")) {
|
||||||
|
addFlag("ORDERED_MAP_FEATURE");
|
||||||
|
if(isModuleEnabled("ArrayMap")) addFlag("ARRAY_MAP_FEATURE");
|
||||||
|
if(hashMap && isModuleEnabled("LinkedHashMap")) addFlag("LINKED_MAP_FEATURE");
|
||||||
|
if(customHashMap && isModuleEnabled("LinkedCustomHashMap")) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||||
|
if(enumMap && isModuleEnabled("LinkedEnumMap")) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||||
|
}
|
||||||
|
if(isModuleEnabled("SortedMap")) {
|
||||||
|
addFlag("SORTED_MAP_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("AVLTreeMap")) addFlag("AVL_TREE_MAP_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("RBTreeMap")) addFlag("RB_TREE_MAP_FEATURE");
|
||||||
|
}
|
||||||
|
if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||||
|
if(hashMap) addFlag("MAP_FEATURE");
|
||||||
|
if(customHashMap) addFlag("CUSTOM_MAP_FEATURE");
|
||||||
|
if(enumMap) addFlag("ENUM_MAP_FEATURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades()
|
||||||
|
{
|
||||||
|
if(!isModuleEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||||
|
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Maps");
|
||||||
|
boolean implementations = !isModuleEnabled("Implementations");
|
||||||
|
if(implementations || !isModuleEnabled("ImmutableMap")) addBlockedFiles("ImmutableOpenHashMap");
|
||||||
|
if(implementations || !isModuleEnabled("ConcurrentMap")) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||||
|
|
||||||
|
boolean ordered = !isModuleEnabled("OrderedMap");
|
||||||
|
if(ordered) addBlockedFiles("OrderedMap");
|
||||||
|
boolean hashMap = implementations || !isModuleEnabled("HashMap");
|
||||||
|
if(hashMap) addBlockedFiles("OpenHashMap");
|
||||||
|
if(hashMap || ordered || !isModuleEnabled("LinkedHashMap")) addBlockedFiles("LinkedOpenHashMap");
|
||||||
|
|
||||||
|
boolean customHashMap = implementations || !isModuleEnabled("CustomHashMap");
|
||||||
|
if(customHashMap) addBlockedFiles("OpenCustomHashMap");
|
||||||
|
if(customHashMap || ordered || !isModuleEnabled("LinkedCustomHashMap")) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||||
|
|
||||||
|
boolean enumMap = implementations || !isModuleEnabled("EnumMap");
|
||||||
|
if(enumMap) addBlockedFiles("EnumMap");
|
||||||
|
if(enumMap || ordered || !isModuleEnabled("LinkedEnumMap")) addBlockedFiles("LinkedEnumMap");
|
||||||
|
|
||||||
|
if(ordered || !isModuleEnabled("ArrayMap")) addBlockedFiles("ArrayMap");
|
||||||
|
|
||||||
|
boolean sorted = !isModuleEnabled("SortedMap");
|
||||||
|
if(sorted) addBlockedFiles("SortedMap", "NavigableMap");
|
||||||
|
if(implementations || sorted || !isModuleEnabled("AVLTreeMap")) addBlockedFiles("AVLTreeMap");
|
||||||
|
if(implementations || sorted || !isModuleEnabled("RBTreeMap")) 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")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers()
|
||||||
|
{
|
||||||
|
//Main Classes
|
||||||
|
addBiRequirement("Map");
|
||||||
|
addBiRequirement("SortedMap");
|
||||||
|
addBiRequirement("OrderedMap");
|
||||||
|
addBiRequirement("NavigableMap");
|
||||||
|
addBiRequirement("ConcurrentMap");
|
||||||
|
addBiRequirement("AbstractMap");
|
||||||
|
addEnumRequirement("EnumMap");
|
||||||
|
addEnumRequirement("LinkedEnumMap");
|
||||||
|
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("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("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("MapToStringTester");
|
||||||
|
addBiRequirement("NavigableMapNavigationTester");
|
||||||
|
addBiRequirement("SortedMapNavigationTester");
|
||||||
|
addBiRequirement("OrderedMapNavigationTester");
|
||||||
|
addBiRequirement("OrderedMapMoveTester");
|
||||||
|
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");
|
||||||
|
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
|
||||||
|
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
|
||||||
|
|
||||||
|
//Abstract Classes
|
||||||
|
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "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,60 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class PairModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new PairModule();
|
||||||
|
@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 Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return new TreeSet<>(Arrays.asList("Mutable", "Immutable")); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {
|
||||||
|
if(isModuleEnabled()) addFlag("PAIR_MODULE");
|
||||||
|
if(isModuleEnabled("Mutable")) addFlag("MUTABLE_PAIR");
|
||||||
|
if(isModuleEnabled("Immutable")) addFlag("IMMUTABLE_PAIR");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades() {
|
||||||
|
if(!isModuleEnabled()) addBlockedFiles("Pair");
|
||||||
|
if(!isModuleEnabled("Mutable")) addBlockedFiles("MutablePair");
|
||||||
|
if(!isModuleEnabled("Immutable")) 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,101 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class PrioQueueModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new PrioQueueModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "PriorityQueue"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions() {}
|
||||||
|
@Override
|
||||||
|
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||||
|
return new TreeSet<>(Arrays.asList("Wrappers", "Implementations", "Dequeue", "FiFoQueue", "HeapQueue", "ArrayPrioQueue"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {
|
||||||
|
if(isModuleEnabled()) addFlag("QUEUE_MODULE");
|
||||||
|
if(isModuleEnabled("Wrappers")) addKeyFlag("QUEUES_FEATURE");
|
||||||
|
boolean implementations = isModuleEnabled("Implementations");
|
||||||
|
if(isModuleEnabled("Dequeue")) {
|
||||||
|
addKeyFlag("DEQUEUE_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("FiFoQueue")) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||||
|
}
|
||||||
|
if(implementations && isModuleEnabled("HeapQueue")) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("ArrayPrioQueue")) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades() {
|
||||||
|
if(!isModuleEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||||
|
if(!isModuleEnabled("Wrappers")) addBlockedFiles("PriorityQueues");
|
||||||
|
boolean implementations = !isModuleEnabled("Implementations");
|
||||||
|
boolean dequeue = !isModuleEnabled("Dequeue");
|
||||||
|
if(dequeue) addBlockedFiles("PriorityDequeue");
|
||||||
|
if(dequeue || implementations || !isModuleEnabled("FiFoQueue")) addBlockedFiles("ArrayFIFOQueue");
|
||||||
|
if(implementations || !isModuleEnabled("HeapQueue")) addBlockedFiles("HeapPriorityQueue");
|
||||||
|
if(implementations || !isModuleEnabled("ArrayPrioQueue")) 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,174 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SetModule extends BaseModule
|
||||||
|
{
|
||||||
|
public static final BaseModule INSTANCE = new SetModule();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Set"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||||
|
@Override
|
||||||
|
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||||
|
@Override
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||||
|
Set<String> sets = new TreeSet<>();
|
||||||
|
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||||
|
sets.addAll(Arrays.asList("OrderedSet", "SortedSet"));
|
||||||
|
sets.addAll(Arrays.asList("ArraySet", "ImmutableSet"));
|
||||||
|
sets.addAll(Arrays.asList("HashSet", "LinkedHashSet"));
|
||||||
|
sets.addAll(Arrays.asList("CustomHashSet", "LinkedCustomHashSet"));
|
||||||
|
sets.addAll(Arrays.asList("AVLTreeSet", "RBTreeSet"));
|
||||||
|
return sets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFlags()
|
||||||
|
{
|
||||||
|
if(isModuleEnabled()) addFlag("SET_MODULE");
|
||||||
|
if(isModuleEnabled("Wrappers")) addFlag("SETS_FEATURE");
|
||||||
|
boolean implementations = isModuleEnabled("Implementations");
|
||||||
|
boolean hashSet = implementations && isModuleEnabled("HashSet");
|
||||||
|
boolean customHashSet = implementations && isModuleEnabled("CustomHashSet");
|
||||||
|
|
||||||
|
if(isModuleEnabled("OrderedSet")) {
|
||||||
|
addFlag("ORDERED_SET_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("ArraySet")) addFlag("ARRAY_SET_FEATURE");
|
||||||
|
if(hashSet && isModuleEnabled("LinkedHashSet")) addFlag("LINKED_SET_FEATURE");
|
||||||
|
if(customHashSet && isModuleEnabled("LinkedCustomHashSet")) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||||
|
}
|
||||||
|
if(isModuleEnabled("SortedSet")) {
|
||||||
|
addFlag("SORTED_SET_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("AVLTreeSet")) addFlag("AVL_TREE_SET_FEATURE");
|
||||||
|
if(implementations && isModuleEnabled("RBTreeSet")) addFlag("RB_TREE_SET_FEATURE");
|
||||||
|
}
|
||||||
|
if(implementations && isModuleEnabled("ImmutableSet")) addFlag("IMMUTABLE_SET_FEATURE");
|
||||||
|
if(hashSet) addFlag("HASH_SET_FEATURE");
|
||||||
|
if(customHashSet) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadBlockades()
|
||||||
|
{
|
||||||
|
if(!isModuleEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||||
|
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Sets");
|
||||||
|
boolean implementations = !isModuleEnabled("Implementations");
|
||||||
|
if(implementations || !isModuleEnabled("ImmutableSet")) addBlockedFiles("ImmutableOpenHashSet");
|
||||||
|
|
||||||
|
boolean ordered = !isModuleEnabled("OrderedSet");
|
||||||
|
if(ordered) addBlockedFiles("OrderedSet");
|
||||||
|
boolean hashSet = implementations || !isModuleEnabled("HashSet");
|
||||||
|
if(hashSet) addBlockedFiles("OpenHashSet");
|
||||||
|
if(hashSet || ordered || !isModuleEnabled("LinkedHashSet")) addBlockedFiles("LinkedOpenHashSet");
|
||||||
|
|
||||||
|
boolean customHashSet = implementations || !isModuleEnabled("CustomHashSet");
|
||||||
|
if(customHashSet) addBlockedFiles("OpenCustomHashSet");
|
||||||
|
if(customHashSet || ordered || !isModuleEnabled("LinkedCustomHashSet")) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||||
|
|
||||||
|
if(implementations || ordered || !isModuleEnabled("ArraySet")) addBlockedFiles("ArraySet");
|
||||||
|
|
||||||
|
boolean sorted = !isModuleEnabled("SortedSet");
|
||||||
|
if(sorted) addBlockedFiles("SortedSet", "NavigableSet");
|
||||||
|
if(implementations || sorted || !isModuleEnabled("AVLTreeSet")) addBlockedFiles("AVLTreeSet");
|
||||||
|
if(implementations || sorted || !isModuleEnabled("RBTreeSet")) 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");
|
||||||
|
|
||||||
|
//Helper Classes
|
||||||
|
addClassMapper("SETS", "Sets");
|
||||||
|
|
||||||
|
//Interfaces
|
||||||
|
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||||
|
addClassMapper("SORTED_SET", "SortedSet");
|
||||||
|
addClassMapper("ORDERED_SET", "OrderedSet");
|
||||||
|
addClassMapper("SET", "Set");
|
||||||
|
}
|
||||||
|
}
|
||||||
+265
-211
@@ -1,212 +1,266 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.AbstractCollection;
|
import java.util.AbstractCollection;
|
||||||
|
#if TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import java.util.function.Consumer;
|
||||||
#if !TYPE_OBJECT
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
|
||||||
#endif
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
/**
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
* Abstract Type Specific Collection that reduces boxing/unboxing
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
* @Type(T)
|
#endif
|
||||||
*/
|
|
||||||
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
/**
|
||||||
{
|
* Abstract Type Specific Collection that reduces boxing/unboxing
|
||||||
@Override
|
* @Type(T)
|
||||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
*/
|
||||||
|
public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractCollection<CLASS_TYPE> implements COLLECTION KEY_GENERIC_TYPE
|
||||||
#if !TYPE_OBJECT
|
{
|
||||||
/** {@inheritDoc}
|
@Override
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
|
||||||
*/
|
#if !TYPE_OBJECT
|
||||||
@Override
|
/** {@inheritDoc}
|
||||||
@Deprecated
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
*/
|
||||||
#endif
|
@Override
|
||||||
@Override
|
@Deprecated
|
||||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean add(CLASS_TYPE e) { return COLLECTION.super.add(e); }
|
||||||
boolean modified = false;
|
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();modified |= add(iter.NEXT()));
|
#endif
|
||||||
return modified;
|
@Override
|
||||||
}
|
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()));
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
return modified;
|
||||||
|
}
|
||||||
#if !TYPE_OBJECT
|
|
||||||
/** {@inheritDoc}
|
@Override
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
|
||||||
*/
|
#if !TYPE_OBJECT
|
||||||
@Override
|
/** {@inheritDoc}
|
||||||
@Deprecated
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
*/
|
||||||
/**
|
@Override
|
||||||
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
@Deprecated
|
||||||
* @param e the element that should be searched for.
|
public boolean contains(Object e) { return COLLECTION.super.contains(e); }
|
||||||
* @return true if the value was found.
|
|
||||||
*/
|
/**
|
||||||
@Override
|
* A Type-Specific implementation of contains. This implementation iterates over the elements and returns true if the value match.
|
||||||
public boolean contains(KEY_TYPE e) {
|
* @param e the element that should be searched for.
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
* @return true if the value was found.
|
||||||
return false;
|
*/
|
||||||
}
|
@Override
|
||||||
|
public boolean contains(KEY_TYPE e) {
|
||||||
/** {@inheritDoc}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { if(KEY_EQUALS(iter.NEXT(), e)) return true; }
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
return false;
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
}
|
||||||
*/
|
|
||||||
@Override
|
/** {@inheritDoc}
|
||||||
@Deprecated
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
{
|
*/
|
||||||
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
@Override
|
||||||
}
|
@Deprecated
|
||||||
#endif
|
public boolean addAll(Collection<? extends CLASS_TYPE> c)
|
||||||
|
{
|
||||||
/**
|
return c instanceof COLLECTION ? addAll((COLLECTION KEY_GENERIC_TYPE)c) : super.addAll(c);
|
||||||
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
}
|
||||||
* @param c the collection that should be checked if it contains all elements.
|
#endif
|
||||||
* @return true if all elements were found in the collection
|
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
/**
|
||||||
*/
|
* A Type-Specific implementation of containsAll. This implementation iterates over all elements and checks all elements are present in the other collection.
|
||||||
@Override
|
* @param c the collection that should be checked if it contains all elements.
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
* @return true if all elements were found in the collection
|
||||||
Objects.requireNonNull(c);
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
*/
|
||||||
if(!contains(iter.NEXT()))
|
@Override
|
||||||
return false;
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
return true;
|
Objects.requireNonNull(c);
|
||||||
}
|
if(c.isEmpty()) return true;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
/**
|
if(!contains(iter.NEXT()))
|
||||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
return false;
|
||||||
* @param c the elements that should be checked for
|
return true;
|
||||||
* @return true if any element is in this collection
|
}
|
||||||
* @deprecated if this is a primitive collection
|
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
@Override
|
||||||
*/
|
public boolean containsAll(Collection<?> c) {
|
||||||
@Override
|
Objects.requireNonNull(c);
|
||||||
@Primitive
|
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||||
public boolean containsAny(Collection<?> c) {
|
}
|
||||||
Objects.requireNonNull(c);
|
|
||||||
for(Object e : c)
|
/**
|
||||||
if(contains(e))
|
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||||
return true;
|
* @param c the elements that should be checked for
|
||||||
return false;
|
* @return true if any element is in this collection
|
||||||
}
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
|
*/
|
||||||
/**
|
@Override
|
||||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
@Primitive
|
||||||
* @param c the elements that should be checked for
|
public boolean containsAny(Collection<?> c) {
|
||||||
* @return true if any element is in this collection
|
Objects.requireNonNull(c);
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
if(c.isEmpty()) return false;
|
||||||
*/
|
for(Object e : c)
|
||||||
@Override
|
if(contains(e))
|
||||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
return true;
|
||||||
Objects.requireNonNull(c);
|
return false;
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
}
|
||||||
if(contains(iter.NEXT()))
|
|
||||||
return true;
|
/**
|
||||||
return false;
|
* This implementation iterates over the elements of the collection and checks if they are stored in this collection.
|
||||||
}
|
* @param c the elements that should be checked for
|
||||||
|
* @return true if any element is in this collection
|
||||||
#if !TYPE_OBJECT
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
/** {@inheritDoc}
|
*/
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
@Override
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
*/
|
Objects.requireNonNull(c);
|
||||||
@Override
|
if(c.isEmpty()) return false;
|
||||||
@Deprecated
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
if(contains(iter.NEXT()))
|
||||||
|
return true;
|
||||||
/**
|
return false;
|
||||||
* 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.
|
}
|
||||||
* It stops after finding the first element
|
|
||||||
* @param e the element that is searched for
|
#if !TYPE_OBJECT
|
||||||
* @return true if the element was found and removed.
|
/** {@inheritDoc}
|
||||||
*/
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
@Override
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
*/
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
@Override
|
||||||
if(KEY_EQUALS(iter.NEXT(), e)) {
|
@Deprecated
|
||||||
iter.remove();
|
public boolean remove(Object e) { return COLLECTION.super.remove(e); }
|
||||||
return true;
|
|
||||||
}
|
/**
|
||||||
}
|
* 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.
|
||||||
return false;
|
* It stops after finding the first element
|
||||||
}
|
* @param e the element that is searched for
|
||||||
|
* @return true if the element was found and removed.
|
||||||
#endif
|
*/
|
||||||
/**
|
@Override
|
||||||
* A Type-Specific implementation of removeAll. This Implementation iterates over all elements and removes them as they were found in the other collection.
|
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||||
* @param c the elements that should be deleted
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
* @return true if the collection was modified.
|
if(KEY_EQUALS(iter.NEXT(), e)) {
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
iter.remove();
|
||||||
*/
|
return true;
|
||||||
@Override
|
}
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
}
|
||||||
Objects.requireNonNull(c);
|
return false;
|
||||||
boolean modified = false;
|
}
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
|
||||||
if(c.contains(iter.NEXT())) {
|
#endif
|
||||||
iter.remove();
|
/**
|
||||||
modified = 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 modified;
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
/**
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE 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.
|
Objects.requireNonNull(c);
|
||||||
* @param c the elements that should be kept
|
if(c.isEmpty()) return false;
|
||||||
* @return true if the collection was modified.
|
boolean modified = false;
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
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) {
|
modified = true;
|
||||||
Objects.requireNonNull(c);
|
}
|
||||||
if(c.isEmpty()) {
|
}
|
||||||
boolean modified = !isEmpty();
|
return modified;
|
||||||
clear();
|
}
|
||||||
return modified;
|
|
||||||
}
|
@Override
|
||||||
boolean modified = false;
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
Objects.requireNonNull(c);
|
||||||
if(!c.contains(iter.NEXT())) {
|
if(c.isEmpty()) return false;
|
||||||
iter.remove();
|
Objects.requireNonNull(r);
|
||||||
modified = true;
|
boolean modified = false;
|
||||||
}
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
}
|
KEY_TYPE e = iter.NEXT();
|
||||||
return modified;
|
if(c.contains(e)) {
|
||||||
}
|
r.accept(e);
|
||||||
|
iter.remove();
|
||||||
#if !TYPE_OBJECT
|
modified = true;
|
||||||
/**
|
}
|
||||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
}
|
||||||
* @return an array containing all of the elements in this collection
|
return modified;
|
||||||
*/
|
}
|
||||||
@Override
|
|
||||||
public KEY_TYPE[] TO_ARRAY() {
|
/**
|
||||||
return TO_ARRAY(new KEY_TYPE[size()]);
|
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||||
}
|
* @param c the elements that should be kept
|
||||||
|
* @return true if the collection was modified.
|
||||||
/**
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
*/
|
||||||
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
@Override
|
||||||
* @return an array containing all of the elements in this collection
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
*/
|
Objects.requireNonNull(c);
|
||||||
@Override
|
if(c.isEmpty()) {
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
boolean modified = !isEmpty();
|
||||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
clear();
|
||||||
ITERATORS.unwrap(a, iterator());
|
return modified;
|
||||||
return a;
|
}
|
||||||
}
|
boolean modified = false;
|
||||||
#endif
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(!c.contains(iter.NEXT())) {
|
||||||
|
iter.remove();
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
|
Objects.requireNonNull(r);
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
boolean modified = !isEmpty();
|
||||||
|
forEach(r);
|
||||||
|
clear();
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
boolean modified = false;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
KEY_TYPE e = iter.NEXT();
|
||||||
|
if(!c.contains(e)) {
|
||||||
|
r.accept(e);
|
||||||
|
iter.remove();
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
|
* @return an array containing all of the elements in this collection
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE[] TO_ARRAY() {
|
||||||
|
if(isEmpty()) return ARRAYS.EMPTY_ARRAY;
|
||||||
|
return TO_ARRAY(new KEY_TYPE[size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type-Specific implementation of toArray. This implementation iterates over all elements and unwraps them into primitive type.
|
||||||
|
* @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
|
||||||
}
|
}
|
||||||
+1
-1
@@ -57,7 +57,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
-240
@@ -1,241 +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;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
#endif
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
#endif
|
||||||
|
#if TYPE_OBJECT
|
||||||
/**
|
import java.util.function.Consumer;
|
||||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
import java.util.function.IntFunction;
|
||||||
* @Type(T)
|
#else
|
||||||
*/
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
|
#endif
|
||||||
{
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
#if !TYPE_OBJECT
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
/**
|
#endif
|
||||||
* A Type-Specific add function to reduce (un)boxing
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||||
* @param o the element that should be added
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
* @return true if the element was added to the collection
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
*/
|
|
||||||
public boolean add(KEY_TYPE o);
|
/**
|
||||||
|
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||||
#endif
|
* @Type(T)
|
||||||
/**
|
*/
|
||||||
* A Type-Specific addAll function to reduce (un)boxing
|
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
* @param c the collection of elements that should be added
|
{
|
||||||
* @return true if elements were added into the collection
|
#if !TYPE_OBJECT
|
||||||
*/
|
/**
|
||||||
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
* A Type-Specific add function to reduce (un)boxing
|
||||||
|
* @param o the element that should be added
|
||||||
/**
|
* @return true if the element was added to the collection
|
||||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
*/
|
||||||
* @param e the elements that should be added
|
public boolean add(KEY_TYPE o);
|
||||||
* @return if the collection was modified
|
|
||||||
*/
|
#endif
|
||||||
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
/**
|
||||||
|
* 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
|
*/
|
||||||
* @param length how many elements of the array should be added
|
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @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
|
||||||
/**
|
* @return if the collection was modified
|
||||||
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
*/
|
||||||
* @param e the elements that should be added
|
public default boolean addAll(KEY_TYPE... e) { return addAll(e, 0, e.length); }
|
||||||
* @param offset where to start within the array
|
|
||||||
* @param length how many elements of the array should be added
|
/**
|
||||||
* @return if the collection was modified
|
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||||
*/
|
* @param e the elements that should be added
|
||||||
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
* @param length how many elements of the array should be added
|
||||||
if(length <= 0) return false;
|
* @return if the collection was modified
|
||||||
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
*/
|
||||||
boolean added = false;
|
public default boolean addAll(KEY_TYPE[] e, int length) { return addAll(e, 0, length); }
|
||||||
for(int i = 0;i<length;i++) {
|
|
||||||
if(add(e[offset+i])) added = true;
|
/**
|
||||||
}
|
* A Type-Specific Array based addAll method to reduce the amount of Wrapping
|
||||||
return added;
|
* @param e the elements that should be added
|
||||||
}
|
* @param offset where to start within the array
|
||||||
|
* @param length how many elements of the array should be added
|
||||||
#if !TYPE_OBJECT
|
* @return if the collection was modified
|
||||||
/**
|
*/
|
||||||
* A Type-Specific contains function to reduce (un)boxing
|
public default boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
||||||
* @param o the element that is checked for
|
if(length <= 0) return false;
|
||||||
* @return true if the element is found in the collection
|
SanityChecks.checkArrayCapacity(e.length, offset, length);
|
||||||
*/
|
boolean added = false;
|
||||||
public boolean contains(KEY_TYPE o);
|
for(int i = 0;i<length;i++) {
|
||||||
|
if(add(e[offset+i])) added = true;
|
||||||
#endif
|
}
|
||||||
/**
|
return added;
|
||||||
* A Type-Specific containsAll function to reduce (un)boxing
|
}
|
||||||
* @param c the collection of elements that should be tested for
|
|
||||||
* @return true if all the element is found in the collection
|
#if !TYPE_OBJECT
|
||||||
*/
|
/**
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
* A Type-Specific contains function to reduce (un)boxing
|
||||||
|
* @param o the element that is checked for
|
||||||
/**
|
* @return true if the element is found in the collection
|
||||||
* A Type-Specific containsAny 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 any element was found
|
|
||||||
*/
|
#endif
|
||||||
public boolean containsAny(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
|
||||||
* Returns true if any element of the Collection is found in the provided collection.
|
* @return true if all the element is found in the collection
|
||||||
* 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 containsAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @return true if any element was found.
|
|
||||||
*/
|
/**
|
||||||
@Primitive
|
* A Type-Specific containsAny function to reduce (un)boxing
|
||||||
public boolean containsAny(Collection<?> c);
|
* @param c the collection of elements that should be tested for
|
||||||
|
* @return true if any element was found
|
||||||
#if !TYPE_OBJECT
|
*/
|
||||||
/**
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* A Type-Specific remove function that reduces (un)boxing.
|
|
||||||
* @param o the element that should be removed
|
/**
|
||||||
* @return true if the element was removed
|
* Returns true if any element of the Collection is found in the provided collection.
|
||||||
* @see Collection#remove(Object)
|
* 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 REMOVE_KEY(KEY_TYPE o);
|
* @return true if any element was found.
|
||||||
|
*/
|
||||||
#endif
|
@Primitive
|
||||||
/**
|
public boolean containsAny(Collection<?> c);
|
||||||
* A Type-Specific removeAll function that reduces (un)boxing.
|
|
||||||
* @param c the collection of elements that should be removed
|
#if !TYPE_OBJECT
|
||||||
* @return true if any element was removed
|
/**
|
||||||
* @see Collection#removeAll(Collection)
|
* A Type-Specific remove function that reduces (un)boxing.
|
||||||
*/
|
* @param o the element that should be removed
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
* @return true if the element was removed
|
||||||
|
* @see Collection#remove(Object)
|
||||||
/**
|
*/
|
||||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
public boolean REMOVE_KEY(KEY_TYPE o);
|
||||||
* @param c the collection of elements that should be kept
|
|
||||||
* @return true if any element was removed
|
#endif
|
||||||
* @see Collection#retainAll(Collection)
|
/**
|
||||||
*/
|
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
* @param c the collection of elements that should be removed
|
||||||
|
* @return true if any element was removed
|
||||||
/**
|
* @see Collection#removeAll(Collection)
|
||||||
* A Function that does a shallow clone of the Collection itself.
|
*/
|
||||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* 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 Type-Specific removeAll function that reduces (un)boxing.
|
||||||
*/
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
* @param c the collection of elements that should be removed
|
||||||
|
* @param r elements that got removed
|
||||||
#if !TYPE_OBJECT
|
* @return true if any element was removed
|
||||||
/**
|
* @see Collection#removeAll(Collection)
|
||||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
*/
|
||||||
* @return an array containing all of the elements in this collection
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
* @see Collection#toArray()
|
|
||||||
*/
|
/**
|
||||||
public KEY_TYPE[] TO_ARRAY();
|
* 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 toArray function that reduces (un)boxing.
|
* @see Collection#retainAll(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
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
* @see Collection#toArray(Object[])
|
|
||||||
*/
|
/**
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||||
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
#if PRIMITIVES
|
* @param c the collection of elements that should be kept
|
||||||
/** {@inheritDoc}
|
* @param r elements that got removed
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
* @return true if any element was removed
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
* @see Collection#retainAll(Collection)
|
||||||
*/
|
*/
|
||||||
@Override
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
@Deprecated
|
|
||||||
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
/**
|
||||||
Objects.requireNonNull(filter);
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
* @param collection that the elements should be inserted to
|
||||||
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
* @param <E> the collection type
|
||||||
#else
|
* @return the input with the desired elements
|
||||||
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
*/
|
||||||
#endif
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
}
|
collection.addAll(this);
|
||||||
|
return collection;
|
||||||
/**
|
}
|
||||||
* A Type-Specific removeIf function to reduce (un)boxing.
|
|
||||||
* <p>Removes elements that were selected by the filter
|
/**
|
||||||
* @see Collection#removeIf(Predicate)
|
* A Function that does a shallow clone of the Collection itself.
|
||||||
* @param filter Filters the elements that should be removed
|
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||||
* @return true if the collection was modified
|
* It can be compared to Cloneable but with less exception risk
|
||||||
* @throws java.lang.NullPointerException if filter is null
|
* @return a Shallow Copy of the collection
|
||||||
*/
|
* @note Wrappers and view collections will not support this feature
|
||||||
public default boolean remIf(JAVA_PREDICATE filter) {
|
*/
|
||||||
Objects.requireNonNull(filter);
|
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||||
boolean removed = false;
|
|
||||||
final ITERATOR each = iterator();
|
#if TYPE_OBJECT
|
||||||
while (each.hasNext()) {
|
/**
|
||||||
if (filter.test(each.NEXT())) {
|
* A Helper function that simplifies the process of creating a new Array.
|
||||||
each.remove();
|
* @param action the array creation function
|
||||||
removed = true;
|
* @param <E> the returning arrayType
|
||||||
}
|
* @return an array containing all of the elements in this collection
|
||||||
}
|
* @see Collection#toArray(Object[])
|
||||||
return removed;
|
*/
|
||||||
}
|
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||||
|
return TO_ARRAY(action.apply(size()));
|
||||||
#endif
|
}
|
||||||
/** {@inheritDoc}
|
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
#else
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
/**
|
||||||
*/
|
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
@Override
|
* @return an array containing all of the elements in this collection
|
||||||
@Deprecated
|
* @see Collection#toArray()
|
||||||
public default boolean add(CLASS_TYPE o) { return add(OBJ_TO_KEY(o)); }
|
*/
|
||||||
|
public KEY_TYPE[] TO_ARRAY();
|
||||||
/** {@inheritDoc}
|
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
/**
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
* A Type-Specific toArray function that reduces (un)boxing.
|
||||||
*/
|
* @param a array that the elements should be injected to. If null or to small a new array with the right size is created
|
||||||
@Override
|
* @return an array containing all of the elements in this collection
|
||||||
@Deprecated
|
* @see Collection#toArray(Object[])
|
||||||
public default boolean contains(Object o) { return o != null && contains(CLASS_TO_KEY(o)); }
|
*/
|
||||||
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a);
|
||||||
/** {@inheritDoc}
|
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
#if PRIMITIVES
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
/** {@inheritDoc}
|
||||||
*/
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
@Override
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
@Deprecated
|
*/
|
||||||
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
@Override
|
||||||
|
@Deprecated
|
||||||
#endif
|
public default boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||||
/**
|
Objects.requireNonNull(filter);
|
||||||
* Returns a Type-Specific Iterator to reduce (un)boxing
|
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||||
* @return a iterator of the collection
|
return remIf(v -> filter.test(KEY_TO_OBJ(SanityChecks.SANITY_CAST(v))));
|
||||||
* @see Collection#iterator()
|
#else
|
||||||
*/
|
return remIf(v -> filter.test(KEY_TO_OBJ(v)));
|
||||||
@Override
|
#endif
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
}
|
||||||
|
|
||||||
#if PRIMITIVES
|
/**
|
||||||
/**
|
* A Type-Specific removeIf function to reduce (un)boxing.
|
||||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
* <p>Removes elements that were selected by the filter
|
||||||
* @return a Stream of the closest java type
|
* @see Collection#removeIf(Predicate)
|
||||||
*/
|
* @param filter Filters the elements that should be removed
|
||||||
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
* @return true if the collection was modified
|
||||||
|
* @throws java.lang.NullPointerException if filter is null
|
||||||
/**
|
*/
|
||||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
public default boolean remIf(JAVA_PREDICATE filter) {
|
||||||
* @return a Stream of the closest java type
|
Objects.requireNonNull(filter);
|
||||||
*/
|
boolean removed = false;
|
||||||
default JAVA_STREAM parallelPrimitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), true); }
|
final ITERATOR each = iterator();
|
||||||
#endif
|
while (each.hasNext()) {
|
||||||
/**
|
if (filter.test(each.NEXT())) {
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
each.remove();
|
||||||
* @return type specific splititerator
|
removed = true;
|
||||||
*/
|
}
|
||||||
@Override
|
}
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/** {@inheritDoc}
|
||||||
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
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.
|
||||||
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@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.
|
||||||
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default boolean remove(Object o) { return o != null && REMOVE_KEY(CLASS_TO_KEY(o)); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Returns a Type-Specific Iterator to reduce (un)boxing
|
||||||
|
* @return a iterator of the collection
|
||||||
|
* @see Collection#iterator()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
|
* @return a new Collection that is synchronized
|
||||||
|
* @see COLLECTIONS#synchronize
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new Collection Wrapper that is synchronized
|
||||||
|
* @see COLLECTIONS#synchronize
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is unmodifiable
|
||||||
|
* @return a new Collection Wrapper that is unmodifiable
|
||||||
|
* @see COLLECTIONS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
|
#if PRIMITIVES
|
||||||
|
/**
|
||||||
|
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||||
|
* @return a Stream of the closest java type
|
||||||
|
*/
|
||||||
|
default JAVA_STREAM primitiveStream() { return StreamSupport.NEW_STREAM(SPLIT_ITERATORS.createJavaSplititerator(this, 0), false); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Java-Type-Specific Parallel 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
|
||||||
|
#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
|
||||||
}
|
}
|
||||||
+457
-186
@@ -1,187 +1,458 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if !TYPE_OBJECT
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Consumer;
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
|
||||||
#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.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
#else
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.IntFunction;
|
||||||
/**
|
import java.util.Comparator;
|
||||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
|
||||||
* @Type(T)
|
#endif
|
||||||
*/
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
{
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
/**
|
#if !JDK_FUNCTION
|
||||||
* Returns an iterator over elements of type {@code T}.
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
*
|
#endif
|
||||||
* @return an Iterator.
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
*/
|
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||||
@Override
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
ITERATOR KEY_GENERIC_TYPE iterator();
|
#if ARRAY_LIST_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
#if !TYPE_OBJECT
|
#else
|
||||||
/**
|
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||||
* A Type Specific foreach function that reduces (un)boxing
|
#endif
|
||||||
*
|
#endif
|
||||||
* @implSpec
|
#if SET_MODULE && !TYPE_BOOLEAN
|
||||||
* <p>The default implementation behaves as if:
|
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||||
* <pre>{@code
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
* iterator().forEachRemaining(action);
|
#if LINKED_SET_FEATURE
|
||||||
* }</pre>
|
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||||
*
|
#else if LINKED_CUSTOM_SET_FEATURE
|
||||||
* @param action The action to be performed for each element
|
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||||
* @throws NullPointerException if the specified action is null
|
#else if SET_FEATURE
|
||||||
* @see Iterable#forEach(Consumer)
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
*/
|
#else if CUSTOM_SET_FEATURE
|
||||||
default void forEach(CONSUMER action) {
|
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||||
Objects.requireNonNull(action);
|
#else if RB_TREE_SET_FEATURE
|
||||||
iterator().forEachRemaining(action);
|
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||||
}
|
#else if AVL_TREE_SET_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||||
/** {@inheritDoc}
|
#else if ARRAY_SET_FEATURE
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
#endif
|
||||||
*/
|
#endif
|
||||||
@Deprecated
|
#endif
|
||||||
@Override
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
#if ASYNC_MODULE
|
||||||
Objects.requireNonNull(action);
|
import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
||||||
iterator().forEachRemaining(action);
|
#endif
|
||||||
}
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
#endif
|
#endif
|
||||||
/**
|
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||||
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
* @param input the object that should be included
|
#if !LINKED_HASH_SET_FEATURE && LINKED_CUSTOM_HASH_SET_FEATURE
|
||||||
* @param action The action to be performed for each element
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
* @param <E> the generic type of the Object
|
#endif
|
||||||
* @throws java.lang.NullPointerException if the specified action is null
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
*/
|
|
||||||
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
/**
|
||||||
Objects.requireNonNull(action);
|
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||||
iterator().forEachRemaining(input, action);
|
* @Type(T)
|
||||||
}
|
*/
|
||||||
|
public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||||
/**
|
{
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
/**
|
||||||
* @return type specific splititerator
|
* Returns an iterator over elements of type {@code T}.
|
||||||
*/
|
*
|
||||||
@Override
|
* @return an Iterator.
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
*/
|
||||||
|
@Override
|
||||||
/**
|
ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
|
||||||
* @param mapper the mapping function
|
#if !TYPE_OBJECT
|
||||||
* @param <E> The return type.
|
/**
|
||||||
* @return a new Iterable that returns the desired result
|
* A Type Specific foreach function that reduces (un)boxing
|
||||||
*/
|
*
|
||||||
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
* @implSpec
|
||||||
return ITERABLES.map(this, mapper);
|
* <p>The default implementation behaves as if:
|
||||||
}
|
* <pre>{@code
|
||||||
|
* iterator().forEachRemaining(action);
|
||||||
/**
|
* }</pre>
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
*
|
||||||
* @param mapper the flatMapping function
|
* @param action The action to be performed for each element
|
||||||
* @param <V> The return type supplier.
|
* @throws NullPointerException if the specified action is null
|
||||||
* @param <E> The return type.
|
* @see Iterable#forEach(Consumer)
|
||||||
* @return a new Iterable that returns the desired result
|
*/
|
||||||
*/
|
default void forEach(CONSUMER action) {
|
||||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
Objects.requireNonNull(action);
|
||||||
return ITERABLES.flatMap(this, mapper);
|
iterator().forEachRemaining(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** {@inheritDoc}
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* @param mapper the flatMapping function
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
* @param <E> The return type.
|
*/
|
||||||
* @return a new Iterable that returns the desired result
|
@Deprecated
|
||||||
*/
|
@Override
|
||||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
default void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
return ITERABLES.arrayFlatMap(this, mapper);
|
Objects.requireNonNull(action);
|
||||||
}
|
iterator().forEachRemaining(action);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
#endif
|
||||||
* @param filter the elements that should be kept.
|
/**
|
||||||
* @return a Iterable that filtered out all unwanted elements
|
* A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
|
||||||
*/
|
* @param action The action to be performed for each element
|
||||||
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
* @throws java.lang.NullPointerException if the specified action is null
|
||||||
return ITERABLES.filter(this, filter);
|
*/
|
||||||
}
|
public default void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
/**
|
int index = 0;
|
||||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();action.accept(index++, iter.NEXT()));
|
||||||
* @param filter that should be applied
|
}
|
||||||
* @return true if any matches were found
|
|
||||||
*/
|
/**
|
||||||
default boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
* Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
|
||||||
Objects.requireNonNull(filter);
|
* @param input the object that should be included
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
* @param action The action to be performed for each element
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) return true;
|
* @param <E> the generic type of the Object
|
||||||
}
|
* @throws java.lang.NullPointerException if the specified action is null
|
||||||
return false;
|
*/
|
||||||
}
|
default <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
/**
|
iterator().forEachRemaining(input, action);
|
||||||
* 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
|
#if SPLIT_ITERATOR_FEATURE
|
||||||
*/
|
/**
|
||||||
default boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
Objects.requireNonNull(filter);
|
* @return type specific splititerator
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
*/
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) return false;
|
@Override
|
||||||
}
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||||
return true;
|
|
||||||
}
|
#endif
|
||||||
|
#if ASYNC_MODULE
|
||||||
/**
|
/**
|
||||||
* Helper function to reduce stream usage that allows to filter for all matches.
|
* Creates a Async Builder for moving work of the thread.
|
||||||
* @param filter that should be applied
|
* 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.
|
||||||
* @return true if all matches.
|
* @see ASYNC_BUILDER
|
||||||
*/
|
* @return a AsyncBuilder
|
||||||
default boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
*/
|
||||||
Objects.requireNonNull(filter);
|
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
return new ASYNC_BUILDERBRACES(this);
|
||||||
if(!filter.TEST_VALUE(iter.NEXT())) return false;
|
}
|
||||||
}
|
|
||||||
return true;
|
#endif
|
||||||
}
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
/**
|
* @param mapper the mapping function
|
||||||
* Helper function to reduce stream usage that allows to filter for the first match.
|
* @param <E> The return type.
|
||||||
* @param filter that should be applied
|
* @return a new Iterable that returns the desired result
|
||||||
* @return the found value or the null equivalent variant.
|
*/
|
||||||
*/
|
default <E> ObjectIterable<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||||
default KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
return ITERABLES.map(this, mapper);
|
||||||
Objects.requireNonNull(filter);
|
}
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
|
||||||
KEY_TYPE entry = iter.NEXT();
|
/**
|
||||||
if(filter.TEST_VALUE(entry)) return entry;
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
}
|
* @param mapper the flatMapping function
|
||||||
return EMPTY_VALUE;
|
* @param <V> The return type supplier.
|
||||||
}
|
* @param <E> The return type.
|
||||||
|
* @return a new Iterable that returns the desired result
|
||||||
/**
|
* @note does not support TO_ARRAY optimizations.
|
||||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
*/
|
||||||
* @param filter that should be applied
|
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
* @return the amount of Valid Elements
|
return ITERABLES.flatMap(this, mapper);
|
||||||
*/
|
}
|
||||||
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
|
||||||
Objects.requireNonNull(filter);
|
/**
|
||||||
int result = 0;
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
* @param mapper the flatMapping function
|
||||||
if(filter.TEST_VALUE(iter.NEXT())) result++;
|
* @param <E> The return type.
|
||||||
}
|
* @return a new Iterable that returns the desired result
|
||||||
return result;
|
* @note does not support TO_ARRAY optimizations.
|
||||||
}
|
*/
|
||||||
|
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
|
return ITERABLES.arrayFlatMap(this, mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||||
|
* @param filter the elements that should be kept.
|
||||||
|
* @return a Iterable that filtered out all unwanted elements
|
||||||
|
* @note does not support TO_ARRAY optimizations.
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
return ITERABLES.filter(this, filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||||
|
* @return a Iterable that filtered out all duplicated elements
|
||||||
|
* @note does not support TO_ARRAY optimizations.
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||||
|
return ITERABLES.distinct(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to repeat elements a desired amount of times
|
||||||
|
* @param repeats how many times the elements should be repeated
|
||||||
|
* @return a Iterable that is repeating multiple times
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE repeat(int repeats) {
|
||||||
|
return ITERABLES.repeat(this, repeats);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @return a Iterable that is limited in length
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||||
|
return ITERABLES.limit(this, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||||
|
* @param sorter that sorts the elements.
|
||||||
|
* @return a Iterable that is sorted
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return ITERABLES.sorted(this, sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||||
|
* @param action the action that should be applied
|
||||||
|
* @return a Peeked Iterable
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return ITERABLES.peek(this, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
|
* @param collection that the elements should be inserted to
|
||||||
|
* @param <E> the collection type
|
||||||
|
* @return the input with the desired elements
|
||||||
|
*/
|
||||||
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
|
ITERATORS.pour(iterator(), collection);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||||
|
* @return a new ArrayList of all elements
|
||||||
|
*/
|
||||||
|
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||||
|
#if ARRAY_LIST_FEATURE
|
||||||
|
return pour(new ARRAY_LISTBRACES());
|
||||||
|
#else
|
||||||
|
return pour(new LINKED_LISTBRACES());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if !TYPE_BOOLEAN && SET_MODULE
|
||||||
|
#if LINKED_SET_FEATURE || LINKED_CUSTOM_SET_FEATURE || SET_FEATURE || CUSTOM_SET_FEATURE || RB_TREE_SET_FEATURE || AVL_TREE_SET_FEATURE || ARRAY_SET_FEATURE
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||||
|
* @return a new LinkedHashSet of all elements
|
||||||
|
*/
|
||||||
|
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||||
|
#if LINKED_SET_FEATURE
|
||||||
|
return pour(new LINKED_HASH_SETBRACES());
|
||||||
|
#else if LINKED_CUSTOM_SET_FEATURE
|
||||||
|
return pour(new LINKED_CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||||
|
#else if SET_FEATURE
|
||||||
|
return pour(new HASH_SETBRACES());
|
||||||
|
#else if CUSTOM_SET_FEATURE
|
||||||
|
return pour(new CUSTOM_HASH_SETBRACES(STRATEGY.normalStrategy()));
|
||||||
|
#else if RB_TREE_SET_FEATURE
|
||||||
|
return pour(new RB_Tree_SETBRACES());
|
||||||
|
#else if AVL_TREE_SET_FEATURE
|
||||||
|
return pour(new AVL_Tree_SETBRACES());
|
||||||
|
#else if ARRAY_SET_FEATURE
|
||||||
|
return pour(new ARRAY_SETBRACES());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||||
|
* @param action is the creator function of said Array to ensure type is kept.
|
||||||
|
* @param <E> the returning arrayType
|
||||||
|
* @return a new Array of all elements
|
||||||
|
*/
|
||||||
|
default <E> E[] TO_ARRAY(IntFunction<E[]> action) {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(this);
|
||||||
|
if(prov != null) {
|
||||||
|
int size = prov.size();
|
||||||
|
if(size >= 0) {
|
||||||
|
E[] array = action.apply(size);
|
||||||
|
ITERATORS.unwrap(array, iterator());
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ARRAYS.pour(iterator(), action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a Array
|
||||||
|
* @return a new Array of all elements
|
||||||
|
*/
|
||||||
|
default KEY_TYPE[] TO_ARRAY() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(this);
|
||||||
|
if(prov != null) {
|
||||||
|
int size = prov.size();
|
||||||
|
if(size >= 0) {
|
||||||
|
KEY_TYPE[] array = NEW_KEY_ARRAY(size);
|
||||||
|
ITERATORS.unwrap(array, iterator());
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ARRAYS.pour(iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* 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 KEY_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 entry;
|
||||||
|
}
|
||||||
|
return EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @Type(E)
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @return the reduction result, returns null value if nothing was found
|
||||||
|
*/
|
||||||
|
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = iter.NEXT();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||||
|
* @param filter that should be applied
|
||||||
|
* @return the amount of Valid Elements
|
||||||
|
*/
|
||||||
|
default int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
int result = 0;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(filter.test(iter.NEXT())) result++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+69
-65
@@ -1,66 +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;
|
||||||
|
|
||||||
public Reversed(COMPARATOR original) {
|
/**
|
||||||
this.original = original;
|
* default constructor
|
||||||
}
|
* @param original that is going to be reversed
|
||||||
|
*/
|
||||||
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
public Reversed(COMPARATOR original) {
|
||||||
return original.compare(o2, o1);
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public int compare(KEY_TYPE o1, KEY_TYPE o2) {
|
||||||
public COMPARATOR reversed() {
|
return original.compare(o2, o1);
|
||||||
return original;
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
public COMPARATOR reversed() {
|
||||||
|
return original;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+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 && PRIMITIVE
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public default KEY_TYPE GET_JAVA() {
|
|
||||||
return GET_KEY();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
|
import java.util.concurrent.RunnableFuture;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
* - 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.
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
||||||
|
/**
|
||||||
|
* Helper function to detect if the task is currently paused.
|
||||||
|
* @return true if paused
|
||||||
|
*/
|
||||||
|
public boolean isPaused();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public void pause();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* This won't be instant, as this function is applied asynchronous.
|
||||||
|
* It will await the pausing of the task.
|
||||||
|
*/
|
||||||
|
public void awaitPausing();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continues the task if it wasn't already completed.
|
||||||
|
* This is done by resubmitting the task to the executor provided.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
* @return true if it was properly completed
|
||||||
|
*/
|
||||||
|
public boolean isSuccessful();
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
||||||
|
*
|
||||||
|
* Waits if necessary for the computation to complete, and then
|
||||||
|
* retrieves its result.
|
||||||
|
*
|
||||||
|
* @return the computed result as primitive
|
||||||
|
* @throws CancellationException if the computation was cancelled
|
||||||
|
* @throws ExecutionException if the computation threw an exception
|
||||||
|
* @throws InterruptedException if the current thread was interrupted
|
||||||
|
* while waiting
|
||||||
|
*/
|
||||||
|
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits if necessary for at most the given time for the computation
|
||||||
|
* to complete, and then retrieves its result, if available.
|
||||||
|
*
|
||||||
|
* @param timeout the maximum time to wait
|
||||||
|
* @param unit the time unit of the timeout argument
|
||||||
|
* @return the computed result as primitive
|
||||||
|
* @throws CancellationException if the computation was cancelled
|
||||||
|
* @throws ExecutionException if the computation threw an exception
|
||||||
|
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||||
|
* @throws TimeoutException if the wait timed out
|
||||||
|
*/
|
||||||
|
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
||||||
|
#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
|
||||||
}
|
}
|
||||||
+210
-86
@@ -3,11 +3,15 @@ package speiger.src.collections.PACKAGE.lists;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
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;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of the {@link LIST} interface.
|
* Abstract implementation of the {@link LIST} interface.
|
||||||
@@ -15,9 +19,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
*/
|
*/
|
||||||
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
#if !TYPE_OBJECT
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific implementation of add function that delegates to {@link #add(int, KEY_TYPE)}
|
* A Type-Specific implementation of add function that delegates to {@link List#add(int, Object)}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE e) {
|
public boolean add(KEY_TYPE e) {
|
||||||
@@ -25,6 +28,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
/** {@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.
|
||||||
@@ -71,7 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return index of the value that was searched for. -1 if not found
|
* @return index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -99,7 +103,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return the last index of the value that was searched for. -1 if not found
|
* @return the last index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -155,6 +159,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) {
|
||||||
|
int index = indexOf(e);
|
||||||
|
if(index == -1) return false;
|
||||||
|
swapRemove(index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares if the list are the same.
|
* Compares if the list are the same.
|
||||||
*/
|
*/
|
||||||
@@ -205,7 +217,8 @@ 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) {
|
||||||
return new SUB_LIST(this, fromIndex, toIndex);
|
SanityChecks.checkArrayCapacity(size(), fromIndex, toIndex-fromIndex);
|
||||||
|
return new SubList(this, 0, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,6 +233,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@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();
|
||||||
return new LIST_ITER(index);
|
return new LIST_ITER(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,124 +245,134 @@ 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 SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
|
private class SubList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
ABSTRACT_LIST KEY_GENERIC_TYPE l;
|
{
|
||||||
int offset;
|
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
|
final int parentOffset;
|
||||||
|
final int offset;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
SUB_LIST(ABSTRACT_LIST KEY_GENERIC_TYPE l, int from, int to) {
|
public SubList(ABSTRACT_LIST KEY_GENERIC_TYPE list, int offset, int from, int to) {
|
||||||
if (from < 0) throw new IndexOutOfBoundsException("fromIndex = " + from);
|
this.list = list;
|
||||||
else if (to > l.size()) throw new IndexOutOfBoundsException("toIndex = " + to);
|
this.parentOffset = from;
|
||||||
else if (from > to) throw new IllegalArgumentException("fromIndex(" + from + ") > toIndex(" + to + ")");
|
this.offset = offset + from;
|
||||||
this.l = l;
|
this.size = to - from;
|
||||||
offset = from;
|
|
||||||
size = to - from;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(int index, KEY_TYPE e) {
|
public void add(int index, KEY_TYPE element) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
l.add(index+offset, e);
|
list.add(parentOffset+index, element);
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
|
||||||
if(length <= 0) return false;
|
|
||||||
l.addElements(this.offset, e, offset, length);
|
|
||||||
offset += length;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
checkRange(from);
|
checkAddSubRange(from);
|
||||||
l.addElements(from + this.offset, a, offset, length);
|
if(length <= 0) return;
|
||||||
size += length;
|
list.addElements(parentOffset+from, a, offset, length);
|
||||||
|
this.size += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
checkRange(from);
|
SanityChecks.checkArrayCapacity(size, from, length);
|
||||||
return l.getElements(from + this.offset, a, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, 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) {
|
||||||
checkRange(from);
|
if(to-from <= 0) return;
|
||||||
checkRange(to);
|
checkSubRange(from);
|
||||||
l.removeElements(from + offset, to + offset);
|
checkAddSubRange(to);
|
||||||
|
list.removeElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= to - from;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> clz) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
checkRange(from);
|
checkSubRange(from);
|
||||||
checkRange(to);
|
checkAddSubRange(to);
|
||||||
K[] a = l.extractElements(from + offset, to + offset, clz);
|
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return a;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
checkRange(from);
|
checkSubRange(from);
|
||||||
checkRange(to);
|
checkAddSubRange(to);
|
||||||
KEY_TYPE[] a = l.extractElements(from + offset, to + offset);
|
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return a;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
return l.GET_KEY(index + offset);
|
return list.GET_KEY(parentOffset+index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||||
|
checkSubRange(index);
|
||||||
|
return list.set(parentOffset+index, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
public KEY_TYPE swapRemove(int index) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
return l.set(index + offset, e);
|
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--;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) {
|
public KEY_TYPE REMOVE(int index) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
|
KEY_TYPE result = list.REMOVE(index+parentOffset);
|
||||||
size--;
|
size--;
|
||||||
return l.REMOVE(index + offset);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -356,17 +380,117 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRange(int index) {
|
@Override
|
||||||
|
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
|
return new SubListIterator(this, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
|
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||||
|
return new SubList(this, offset, fromIndex, toIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkSubRange(int index) {
|
||||||
if (index < 0 || index >= size)
|
if (index < 0 || index >= size)
|
||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAddRange(int index) {
|
protected void checkAddSubRange(int index) {
|
||||||
if (index < 0 || index > size)
|
if (index < 0 || index > size)
|
||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SubListIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
|
int index;
|
||||||
|
int lastReturned = -1;
|
||||||
|
|
||||||
|
SubListIterator(ABSTRACT_LIST KEY_GENERIC_TYPE list, int index) {
|
||||||
|
this.list = list;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return index < list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
int i = index++;
|
||||||
|
return list.GET_KEY((lastReturned = i));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPrevious() {
|
||||||
|
return index > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
index--;
|
||||||
|
return list.GET_KEY((lastReturned = index));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int previousIndex() {
|
||||||
|
return index-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
|
list.REMOVE(lastReturned);
|
||||||
|
index = lastReturned;
|
||||||
|
lastReturned = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(KEY_TYPE e) {
|
||||||
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
|
list.set(lastReturned, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(KEY_TYPE e) {
|
||||||
|
list.add(index, e);
|
||||||
|
index++;
|
||||||
|
lastReturned = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, size() - index);
|
||||||
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, index);
|
||||||
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||||
|
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;
|
||||||
@@ -382,8 +506,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
lastReturned = index;
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return GET_KEY(index++);
|
int i = index++;
|
||||||
|
return GET_KEY((lastReturned = i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -393,8 +518,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
lastReturned = index;
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return GET_KEY(index--);
|
index--;
|
||||||
|
return GET_KEY((lastReturned = index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -409,34 +535,31 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
||||||
if(lastReturned < index)
|
index = lastReturned;
|
||||||
index--;
|
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(KEY_TYPE e) {
|
public void set(KEY_TYPE e) {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
if(lastReturned == -1)
|
ABSTRACT_LIST.this.add(index, e);
|
||||||
throw new IllegalStateException();
|
index++;
|
||||||
ABSTRACT_LIST.this.add(index++, e);
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,6 +568,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.min(index, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1199
-1064
File diff suppressed because it is too large
Load Diff
+2191
File diff suppressed because it is too large
Load Diff
+142
-9
@@ -5,14 +5,21 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
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
|
||||||
|
|
||||||
@@ -23,15 +30,20 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
|||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.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 PRIMITIVES && SPLIT_ITERATOR_FEATURE && STREAM_FEATURE
|
||||||
import java.util.stream.JAVA_STREAM;
|
import java.util.stream.JAVA_STREAM;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
#endif
|
#endif
|
||||||
|
#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.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
|
||||||
@@ -126,7 +138,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
SanityChecks.checkArrayCapacity(data.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
|
SanityChecks.checkArrayCapacity(data.length, from, length);
|
||||||
System.arraycopy(data, from, a, offset, length);
|
System.arraycopy(data, from, a, offset, length);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -298,7 +311,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;
|
||||||
}
|
}
|
||||||
@@ -307,7 +320,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;
|
||||||
}
|
}
|
||||||
@@ -316,7 +329,7 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -325,21 +338,66 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_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 data[i];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = data[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
|
return new LIST_ITER(index);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -351,7 +409,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE_KEY(KEY_TYPE type) { throw new UnsupportedOperationException(); }
|
public boolean REMOVE_KEY(KEY_TYPE type) { throw new UnsupportedOperationException(); }
|
||||||
@@ -370,6 +429,10 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
@@ -383,6 +446,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public Object[] toArray() {
|
public Object[] toArray() {
|
||||||
|
if(data.length == 0) return ObjectArrays.EMPTY_ARRAY;
|
||||||
Object[] obj = new Object[data.length];
|
Object[] obj = new Object[data.length];
|
||||||
for(int i = 0,m=data.length;i<m;i++)
|
for(int i = 0,m=data.length;i<m;i++)
|
||||||
obj[i] = KEY_TO_OBJ(data[i]);
|
obj[i] = KEY_TO_OBJ(data[i]);
|
||||||
@@ -401,6 +465,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
|
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
|
||||||
for(int i = 0,m=data.length;i<m;i++)
|
for(int i = 0,m=data.length;i<m;i++)
|
||||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||||
|
if (a.length > data.length) a[data.length] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +474,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a.length < data.length) a = new KEY_TYPE[data.length];
|
if(a.length < data.length) a = new KEY_TYPE[data.length];
|
||||||
System.arraycopy(data, 0, a, 0, data.length);
|
System.arraycopy(data, 0, a, 0, data.length);
|
||||||
|
if (a.length > data.length) a[data.length] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,7 +498,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
|
||||||
@@ -449,4 +516,70 @@ 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 {
|
||||||
|
int index;
|
||||||
|
|
||||||
|
LIST_ITER(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return index < size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return GET_KEY(index++);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPrevious() {
|
||||||
|
return index > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
return GET_KEY(--index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int previousIndex() {
|
||||||
|
return index-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, size() - 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1399
-1176
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+62
-15
@@ -3,15 +3,22 @@ package speiger.src.collections.PACKAGE.maps.abstracts;
|
|||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if VALUE_BOOLEAN && JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
|
#if !VALUE_BOOLEAN || !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
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 +26,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
|
||||||
@@ -47,9 +55,25 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
@@ -63,14 +87,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());
|
||||||
}
|
}
|
||||||
@@ -90,9 +114,18 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||||
|
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||||
|
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||||
|
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,14 +185,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()));
|
||||||
}
|
}
|
||||||
@@ -186,7 +219,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
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;
|
||||||
@@ -200,7 +233,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
Objects.requireNonNull(valueProvider);
|
Objects.requireNonNull(valueProvider);
|
||||||
VALUE_TYPE value;
|
VALUE_TYPE value;
|
||||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||||
put(key, newValue);
|
put(key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
@@ -237,7 +270,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());
|
||||||
@@ -276,10 +309,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());
|
||||||
}
|
}
|
||||||
@@ -297,7 +340,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
|
||||||
@@ -309,7 +356,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();
|
||||||
@@ -360,7 +407,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();
|
||||||
@@ -400,7 +447,7 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -495,7 +542,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(key) + "->" + VALUE_TO_STRING(value);
|
return KEY_TO_STRING(key) + "=" + VALUE_TO_STRING(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2526
File diff suppressed because it is too large
Load Diff
+1513
-1364
File diff suppressed because it is too large
Load Diff
+1555
-1301
File diff suppressed because it is too large
Load Diff
+1512
-1342
File diff suppressed because it is too large
Load Diff
+1510
-1261
File diff suppressed because it is too large
Load Diff
+1407
-1222
File diff suppressed because it is too large
Load Diff
+1457
-2274
File diff suppressed because it is too large
Load Diff
+738
-381
File diff suppressed because it is too large
Load Diff
+963
-860
File diff suppressed because it is too large
Load Diff
+2918
-2429
File diff suppressed because it is too large
Load Diff
+2990
-2501
File diff suppressed because it is too large
Load Diff
+95
@@ -0,0 +1,95 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||||
|
* Since the interface adds nothing new. It is there just for completion sake.
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||||
|
MAP.super.forEach(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@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) {
|
||||||
|
return MAP.super.merge(key, value, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object key, Object value);
|
||||||
|
@Override
|
||||||
|
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Primitive
|
||||||
|
@Override
|
||||||
|
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||||
|
return MAP.super.getOrDefault(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
|
return MAP.super.putIfAbsent(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default boolean remove(Object key, Object value) {
|
||||||
|
return MAP.super.remove(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||||
|
return MAP.super.replace(key, oldValue, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
|
return MAP.super.replace(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
MAP.super.replaceAll(mappingFunction);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1194
-510
File diff suppressed because it is too large
Load Diff
+34
-4
@@ -2,6 +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;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Navigable Map interface with a couple helper methods
|
* A Type Specific Navigable Map interface with a couple helper methods
|
||||||
@@ -33,7 +36,34 @@ 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
|
||||||
|
* @return a new NavigableMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new NavigableMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableMap that is unmodifiable
|
||||||
|
* @return a new NavigableMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -184,13 +214,13 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
|||||||
default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey), true); }
|
default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey), true); }
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(CLASS_TYPE key) { return lowerEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(CLASS_TYPE key) { return floorEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(CLASS_TYPE key) { return ceilingEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(CLASS_TYPE key) { return higherEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(CLASS_TYPE key);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive);
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive);
|
||||||
|
|||||||
+149
@@ -0,0 +1,149 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
|
#if MAPS_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
#endif
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
|
/**
|
||||||
|
* A Special Map Interface giving Access to some really usefull functions
|
||||||
|
* The Idea behind this interface is to allow access to functions that give control to the Order of elements.
|
||||||
|
* Since Linked implementations as examples can be reordered outside of the Insertion Order.
|
||||||
|
* This interface provides basic access to such functions while also providing some Sorted/NaivgableMap implementations that still fit into here.
|
||||||
|
*
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A customized put method that allows you to insert into the first index.
|
||||||
|
* @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 putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
|
||||||
|
* @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 putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key/value to the first index.
|
||||||
|
* @param key that should be moved to the first index
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToFirst(KEY_TYPE key);
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key/value to the last index.
|
||||||
|
* @param key that should be moved to the first last
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToLast(KEY_TYPE key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Specific get method that allows to move teh given key/value int the first index.
|
||||||
|
* @param key that is searched for
|
||||||
|
* @return the given value for the requested key or default return value
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
|
||||||
|
/**
|
||||||
|
* A Specific get method that allows to move teh given key/value int the last index.
|
||||||
|
* @param key that is searched for
|
||||||
|
* @return the given value for the requested key or default return value
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first Key of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE FIRST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the first Key of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get the last Key of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE LAST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the last Key of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_LAST_ENTRY_KEY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first Value of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE FIRST_ENTRY_VALUE();
|
||||||
|
/**
|
||||||
|
* A method to get the last Value of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||||
|
|
||||||
|
#if MAPS_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @return a new SortedMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is unmodifiable
|
||||||
|
* @return a new SortedMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
interface FastOrderedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
|
@Override
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||||
|
/**
|
||||||
|
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||||
|
* @param fromElement that is going to be started from.
|
||||||
|
* @return a improved iterator that starts from the desired element
|
||||||
|
*/
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
-56
@@ -9,8 +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;
|
||||||
|
#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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,60 +23,11 @@ import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
|||||||
*
|
*
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
|
* @note ORDERED_MAP is only extended until 0.6.0 for Compat reasons.
|
||||||
|
* The supported classes already implement ORDERED_MAP directly and will remove SORTED_MAP implementations in favor of ORDERED_MAP instead
|
||||||
*/
|
*/
|
||||||
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* A customized put method that allows you to insert into the first index.
|
|
||||||
* @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)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
|
|
||||||
/**
|
|
||||||
* A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
|
|
||||||
* @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)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key/value to the first index.
|
|
||||||
* @param key that should be moved to the first index
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToFirst(KEY_TYPE key);
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key/value to the last index.
|
|
||||||
* @param key that should be moved to the first last
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToLast(KEY_TYPE key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Specific get method that allows to move teh given key/value int the first index.
|
|
||||||
* @param key that is searched for
|
|
||||||
* @return the given value for the requested key or default return value
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
|
|
||||||
/**
|
|
||||||
* A Specific get method that allows to move teh given key/value int the last index.
|
|
||||||
* @param key that is searched for
|
|
||||||
* @return the given value for the requested key or default return value
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||||
|
|
||||||
@@ -79,10 +35,34 @@ 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
|
||||||
|
* @return a new SortedMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is unmodifiable
|
||||||
|
* @return a new SortedMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -181,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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,6 +176,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
|||||||
interface FastSortedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
interface FastSortedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
@Override
|
@Override
|
||||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||||
|
/**
|
||||||
|
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||||
|
* @param fromElement that is going to be started from.
|
||||||
|
* @return a improved iterator that starts from the desired element
|
||||||
|
*/
|
||||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+76
-13
@@ -4,17 +4,25 @@ 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;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.utils.ITrimmable;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,7 +88,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
*/
|
*/
|
||||||
public ARRAY_FIFO_QUEUE(int capacity) {
|
public ARRAY_FIFO_QUEUE(int capacity) {
|
||||||
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
||||||
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity));
|
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity+1));
|
||||||
minCapacity = array.length;
|
minCapacity = array.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,16 +112,21 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
if(first != last) {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
Arrays.fill(array, null);
|
Arrays.fill(array, null);
|
||||||
#endif
|
#endif
|
||||||
first = last = 0;
|
first = last = 0;
|
||||||
|
}
|
||||||
|
else if(first != 0) {
|
||||||
|
first = last = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enqueue(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
array[last] = e;
|
array[last++] = e;
|
||||||
last = ++last % array.length;
|
if(last == array.length) last = 0;
|
||||||
if(last == first) expand();
|
if(last == first) expand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +144,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
array[first] = null;
|
array[first] = null;
|
||||||
#endif
|
#endif
|
||||||
first = ++first % array.length;
|
if(++first == array.length) first = 0;
|
||||||
reduce();
|
reduce();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -150,8 +163,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE peek(int index) {
|
public KEY_TYPE peek(int index) {
|
||||||
if(first == last || index < 0 || index > size()) throw new NoSuchElementException();
|
if(first == last || index < 0 || index >= size()) throw new NoSuchElementException();
|
||||||
return array[(first + index) % array.length];
|
index += first;
|
||||||
|
return index >= array.length ? array[index-array.length] : array[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -249,6 +263,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
clearAndTrim(0);
|
clearAndTrim(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
if(first == last) return;
|
||||||
|
for(int i = 0,m=size();i<m;i++)
|
||||||
|
action.accept(i, array[(first + i) % array.length]);
|
||||||
|
clearAndTrim(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -262,7 +285,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
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=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return true;
|
if(filter.test(array[(first + i) % array.length])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -271,7 +294,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
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=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
if(filter.test(array[(first + i) % array.length])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -280,7 +303,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
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=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
if(!filter.TEST_VALUE(array[(first + i) % array.length])) return false;
|
if(!filter.test(array[(first + i) % array.length])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -290,7 +313,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
int index = (first + i) % array.length;
|
int index = (first + i) % array.length;
|
||||||
if(filter.TEST_VALUE(array[index])) {
|
if(filter.test(array[index])) {
|
||||||
KEY_TYPE data = array[index];
|
KEY_TYPE data = array[index];
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
return data;
|
return data;
|
||||||
@@ -299,12 +322,51 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[(first + i) % array.length];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for(int i = 0,m=size();i<m;i++) {
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
if(filter.TEST_VALUE(array[(first + i) % array.length])) result++;
|
if(filter.test(array[(first + i) % array.length])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -387,6 +449,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
KEY_TYPE value = array[index];
|
KEY_TYPE value = array[index];
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
index = ++index % array.length;
|
index = ++index % array.length;
|
||||||
|
|||||||
+68
-7
@@ -5,8 +5,12 @@ 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;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
@@ -14,9 +18,14 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
||||||
@@ -68,7 +77,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
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");
|
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
this.size = size;
|
|
||||||
comparator = comp;
|
comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +193,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enqueue(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
if(size == array.length) array = Arrays.copyOf(array, size+1);
|
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){
|
if(firstIndex != -1){
|
||||||
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
||||||
if(compare < 0) firstIndex = size;
|
if(compare < 0) firstIndex = size;
|
||||||
@@ -207,6 +215,13 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE first() {
|
||||||
|
if(isEmpty()) throw new NoSuchElementException();
|
||||||
|
if(firstIndex == -1) findFirstIndex();
|
||||||
|
return array[firstIndex];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE peek(int index) {
|
public KEY_TYPE peek(int index) {
|
||||||
if(index < 0 || index >= size) throw new NoSuchElementException();
|
if(index < 0 || index >= size) throw new NoSuchElementException();
|
||||||
@@ -261,6 +276,12 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -271,7 +292,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
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(array[i])) return true;
|
if(filter.test(array[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -280,7 +301,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
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(array[i])) return false;
|
if(filter.test(array[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -289,16 +310,55 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
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(array[i])) return false;
|
if(!filter.test(array[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_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(array[i])) {
|
if(filter.test(array[i])) {
|
||||||
KEY_TYPE data = array[i];
|
KEY_TYPE data = array[i];
|
||||||
removeIndex(i);
|
removeIndex(i);
|
||||||
return data;
|
return data;
|
||||||
@@ -312,7 +372,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
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(array[i])) result++;
|
if(filter.test(array[i])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -373,6 +433,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return dequeue();
|
return dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-7
@@ -5,8 +5,12 @@ 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;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
@@ -14,9 +18,14 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Simple Heap base Priority Queue implementation
|
* A Simple Heap base Priority Queue implementation
|
||||||
@@ -64,7 +73,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
*/
|
*/
|
||||||
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
this.size = size;
|
|
||||||
comparator = comp;
|
comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +213,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enqueue(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
if(size == array.length) array = Arrays.copyOf(array, size + 1);
|
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));
|
||||||
array[size++] = e;
|
array[size++] = e;
|
||||||
ARRAYS.shiftUp(array, size-1, comparator);
|
ARRAYS.shiftUp(array, size-1, comparator);
|
||||||
}
|
}
|
||||||
@@ -248,6 +256,12 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
for(int i = 0,m=size;i<m;i++) action.accept(dequeue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(int i = 0,m=size;i<m;i++) action.accept(i, dequeue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -258,7 +272,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
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(array[i])) return true;
|
if(filter.test(array[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -267,7 +281,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
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(array[i])) return false;
|
if(filter.test(array[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -276,16 +290,55 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
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(array[i])) return false;
|
if(!filter.test(array[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_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(array[i])) {
|
if(filter.test(array[i])) {
|
||||||
KEY_TYPE data = array[i];
|
KEY_TYPE data = array[i];
|
||||||
removeIndex(i);
|
removeIndex(i);
|
||||||
return data;
|
return data;
|
||||||
@@ -299,7 +352,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
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(array[i])) result++;
|
if(filter.test(array[i])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -348,6 +401,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return dequeue();
|
return dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -6,6 +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;
|
||||||
|
#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.
|
||||||
@@ -80,6 +83,23 @@ 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
|
||||||
|
* @return a new PriorityDequeue that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new PriorityDequeue Wrapper that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||||
}
|
}
|
||||||
+195
-160
@@ -1,161 +1,196 @@
|
|||||||
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;
|
||||||
#else
|
import java.util.function.IntFunction;
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
#else
|
||||||
#endif
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
/**
|
#if QUEUES_FEATURE
|
||||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||||
* @Type(T)
|
#endif
|
||||||
*/
|
|
||||||
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
|
||||||
{
|
/**
|
||||||
/**
|
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||||
* @return true if the PriorityQueue is empty
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public default boolean isEmpty() { return size() <= 0; }
|
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
|
||||||
/**
|
{
|
||||||
* @return the amount of elements that are stored in the PriorityQueue
|
/**
|
||||||
*/
|
* @return true if the PriorityQueue is empty
|
||||||
public int size();
|
*/
|
||||||
/**
|
public default boolean isEmpty() { return size() <= 0; }
|
||||||
* clears all elements within the PriorityQueue,
|
/**
|
||||||
* this does not resize the backing arrays
|
* @return the amount of elements that are stored in the PriorityQueue
|
||||||
*/
|
*/
|
||||||
public void clear();
|
public int size();
|
||||||
|
/**
|
||||||
/**
|
* clears all elements within the PriorityQueue,
|
||||||
* Method to insert a element into the PriorityQueue
|
* this does not resize the backing arrays
|
||||||
* @param e the element that should be inserted
|
*/
|
||||||
*/
|
public void clear();
|
||||||
public void enqueue(KEY_TYPE e);
|
|
||||||
|
/**
|
||||||
/**
|
* Method to insert a element into the PriorityQueue
|
||||||
* Method to mass insert elements into the PriorityQueue
|
* @param e the element that should be inserted
|
||||||
* @param e the elements that should be inserted
|
*/
|
||||||
*/
|
public void enqueue(KEY_TYPE e);
|
||||||
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
|
public default void enqueueAll(KEY_TYPE... e) {
|
||||||
* @param e the elements that should be inserted
|
enqueueAll(e, 0, e.length);
|
||||||
* @param length the amount of elements that should be inserted
|
}
|
||||||
*/
|
|
||||||
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
/**
|
||||||
enqueueAll(e, 0, length);
|
* Method to mass insert elements into the PriorityQueue
|
||||||
}
|
* @param e the elements that should be inserted
|
||||||
|
* @param length the amount of elements that should be inserted
|
||||||
/**
|
*/
|
||||||
* Method to mass insert elements into the PriorityQueue
|
public default void enqueueAll(KEY_TYPE[] e, int length) {
|
||||||
* @param e the elements that should be inserted
|
enqueueAll(e, 0, length);
|
||||||
* @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) {
|
* Method to mass insert elements into the PriorityQueue
|
||||||
for(int i = 0;i<length;i++)
|
* @param e the elements that should be inserted
|
||||||
enqueue(e[i+offset]);
|
* @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) {
|
||||||
* Method to mass insert elements into the PriorityQueue
|
for(int i = 0;i<length;i++)
|
||||||
* @param c the elements that should be inserted from the Collection
|
enqueue(e[i+offset]);
|
||||||
*/
|
}
|
||||||
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
/**
|
||||||
enqueue(iter.NEXT());
|
* Method to mass insert elements into the PriorityQueue
|
||||||
}
|
* @param c the elements that should be inserted from the Collection
|
||||||
|
*/
|
||||||
#if TYPE_OBJECT
|
public default void enqueueAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
/**
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
* Method to mass insert elements into the PriorityQueue
|
enqueue(iter.NEXT());
|
||||||
* 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
|
|
||||||
*/
|
#if TYPE_OBJECT
|
||||||
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
/**
|
||||||
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
* Method to mass insert elements into the PriorityQueue
|
||||||
enqueue(iter.next());
|
* 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
|
||||||
|
*/
|
||||||
#endif
|
public default void enqueueAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
|
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
||||||
/**
|
enqueue(iter.next());
|
||||||
* Method to extract a element from the PriorityQueue
|
}
|
||||||
* @return a element from the Queue
|
|
||||||
* @throws java.util.NoSuchElementException if no element is present
|
#endif
|
||||||
*/
|
|
||||||
public KEY_TYPE dequeue();
|
/**
|
||||||
|
* Method to extract a element from the PriorityQueue
|
||||||
/**
|
* @return a element from the Queue
|
||||||
* Peeking function to see whats inside the queue.
|
* @throws java.util.NoSuchElementException if no element is present
|
||||||
* @param index of the element that is requested to be viewed.
|
*/
|
||||||
* @return the element that is requested
|
public KEY_TYPE dequeue();
|
||||||
*/
|
|
||||||
public KEY_TYPE peek(int index);
|
/**
|
||||||
/**
|
* Peeking function to see whats inside the queue.
|
||||||
* Shows the element that is to be returned next
|
* @param index of the element that is requested to be viewed.
|
||||||
* @return the first element in the Queue
|
* @return the element that is requested
|
||||||
*/
|
*/
|
||||||
public default KEY_TYPE first() { return peek(0); }
|
public KEY_TYPE peek(int index);
|
||||||
|
/**
|
||||||
/**
|
* Shows the element that is to be returned next
|
||||||
* Removes the first found element in the queue
|
* @return the first element in the Queue
|
||||||
* @param e the element that should be removed
|
*/
|
||||||
* @return if a searched element was removed
|
public default KEY_TYPE first() { return peek(0); }
|
||||||
*/
|
|
||||||
public boolean removeFirst(KEY_TYPE e);
|
/**
|
||||||
/**
|
* Removes the first found element in the queue
|
||||||
* Removes the last found element in the queue
|
* @param e the element that should be removed
|
||||||
* @param e the element that should be removed
|
* @return if a searched element was removed
|
||||||
* @return if a searched element was removed
|
*/
|
||||||
*/
|
public boolean removeFirst(KEY_TYPE e);
|
||||||
public boolean removeLast(KEY_TYPE e);
|
/**
|
||||||
|
* Removes the last found element in the queue
|
||||||
/**
|
* @param e the element that should be removed
|
||||||
* Allows to notify the Queue to be revalidate its data
|
* @return if a searched element was removed
|
||||||
*/
|
*/
|
||||||
public void onChanged();
|
public boolean removeLast(KEY_TYPE e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Function that does a shallow clone of the PriorityQueue itself.
|
* Allows to notify the Queue to be revalidate its data
|
||||||
* 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 void onChanged();
|
||||||
* @return a Shallow Copy of the PriorityQueue
|
|
||||||
* @note Wrappers and view PriorityQueues will not support this feature
|
/**
|
||||||
*/
|
* A Function that does a shallow clone of the PriorityQueue itself.
|
||||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
* 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
|
||||||
* @return the sorter of the Queue, can be null
|
* @note Wrappers and view PriorityQueues will not support this feature
|
||||||
*/
|
*/
|
||||||
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
/**
|
||||||
/**
|
* @return the sorter of the Queue, can be null
|
||||||
* @return draining iterator of the PriorityQueue
|
*/
|
||||||
*/
|
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
|
||||||
#endif
|
#if TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A method to drop the contents of the Queue without clearing the queue
|
* @return draining iterator of the PriorityQueue
|
||||||
* @Type(E)
|
*/
|
||||||
* @return the contents of the queue into a seperate array.
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
*/
|
|
||||||
public default GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
|
#endif
|
||||||
/**
|
#if QUEUES_FEATURE
|
||||||
* A method to drop the contents of the Queue without clearing the queue
|
/**
|
||||||
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
* @Type(E)
|
* @return a new PriorityQueue that is synchronized
|
||||||
* @return the contents of the queue into a seperate array.
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
*/
|
||||||
*/
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new PriorityQueue Wrapper that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* A method to drop the contents of the Queue without clearing the queue
|
||||||
|
* @Type(E)
|
||||||
|
* @return the contents of the queue 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 Queue without clearing the queue
|
||||||
|
* @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 queue 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);
|
||||||
|
#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
|
||||||
}
|
}
|
||||||
+1668
-1334
File diff suppressed because it is too large
Load Diff
+50
-58
@@ -1,58 +1,50 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
import java.util.Iterator;
|
#if TYPE_OBJECT
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
#endif
|
||||||
|
import java.util.Set;
|
||||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||||
|
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
|
||||||
@Override
|
{
|
||||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
#endif
|
||||||
public int hashCode() {
|
@Override
|
||||||
int hashCode = 1;
|
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
@Override
|
||||||
while(i.hasNext())
|
public ABSTRACT_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||||
hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT());
|
|
||||||
return hashCode;
|
@Override
|
||||||
}
|
public int hashCode() {
|
||||||
|
int hashCode = 0;
|
||||||
@Override
|
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||||
public boolean equals(Object o) {
|
while(i.hasNext())
|
||||||
if (o == this)
|
hashCode += KEY_TO_HASH(i.NEXT());
|
||||||
return true;
|
return hashCode;
|
||||||
if (!(o instanceof Set))
|
}
|
||||||
return false;
|
|
||||||
Set<?> l = (Set<?>)o;
|
@Override
|
||||||
if(l.size() != size()) return false;
|
public boolean equals(Object o) {
|
||||||
#if !TYPE_OBJECT
|
if (o == this)
|
||||||
if(l instanceof SET)
|
return true;
|
||||||
{
|
if (!(o instanceof Set))
|
||||||
ITERATOR e1 = iterator();
|
return false;
|
||||||
ITERATOR e2 = ((SET)l).iterator();
|
Set<?> l = (Set<?>)o;
|
||||||
while (e1.hasNext() && e2.hasNext()) {
|
if(l.size() != size()) return false;
|
||||||
if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT())))
|
try {
|
||||||
return false;
|
return containsAll(l);
|
||||||
}
|
} catch (ClassCastException | NullPointerException unused) {
|
||||||
return !(e1.hasNext() || e2.hasNext());
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
Iterator<CLASS_TYPE> e1 = iterator();
|
}
|
||||||
Iterator<?> e2 = l.iterator();
|
|
||||||
while (e1.hasNext() && e2.hasNext()) {
|
|
||||||
if(!Objects.equals(e1.next(), e2.next()))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !(e1.hasNext() || e2.hasNext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+117
-384
@@ -3,23 +3,29 @@ package speiger.src.collections.PACKAGE.sets;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
#if PRIMITIVES
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
#if PRIMITIVES && !JDK_FUNCTION
|
||||||
import java.util.function.JAVA_PREDICATE;
|
import java.util.function.JAVA_PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
#endif
|
#endif
|
||||||
@@ -34,7 +40,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
|||||||
* This implementation does not shrink the backing array
|
* This implementation does not shrink the backing array
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing Array */
|
/** The Backing Array */
|
||||||
protected transient KEY_TYPE[] data;
|
protected transient KEY_TYPE[] data;
|
||||||
@@ -54,6 +60,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +79,8 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
* @throws NegativeArraySizeException if the length is negative
|
* @throws NegativeArraySizeException if the length is negative
|
||||||
*/
|
*/
|
||||||
public ARRAY_SET(KEY_TYPE[] array, int length) {
|
public ARRAY_SET(KEY_TYPE[] array, int length) {
|
||||||
data = Arrays.copyOf(array, length);
|
this(length);
|
||||||
size = length;
|
addAll(array, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,6 +137,17 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
int index = findIndex(o);
|
||||||
|
if(index != -1) return data[index];
|
||||||
|
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||||
|
data[size++] = o;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||||
int index = findIndex(o);
|
int index = findIndex(o);
|
||||||
@@ -157,7 +175,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;
|
||||||
@@ -227,6 +245,21 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(!c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean result = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@@ -242,6 +275,21 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean result = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean removeAll(Collection<?> c) {
|
public boolean removeAll(Collection<?> c) {
|
||||||
@@ -349,6 +397,12 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
for(int i = 0;i<size;action.accept(data[i++]));
|
for(int i = 0;i<size;action.accept(data[i++]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
for(int i = 0;i<size;action.accept(i, data[i++]));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -360,7 +414,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;
|
||||||
}
|
}
|
||||||
@@ -369,7 +423,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;
|
||||||
}
|
}
|
||||||
@@ -378,7 +432,7 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -387,17 +441,56 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_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 data[i];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = data[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -428,28 +521,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
||||||
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
||||||
set.data = Arrays.copyOf(data, data.length);
|
set.data = Arrays.copyOf(data, data.length);
|
||||||
@@ -457,11 +528,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
size = 0;
|
size = 0;
|
||||||
@@ -477,6 +543,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a == null || a.length < size()) return Arrays.copyOf(data, size());
|
if(a == null || a.length < size()) return Arrays.copyOf(data, size());
|
||||||
System.arraycopy(data, 0, a, 0, size());
|
System.arraycopy(data, 0, a, 0, size());
|
||||||
|
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,6 +551,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Object[] toArray() {
|
public Object[] toArray() {
|
||||||
|
if(isEmpty()) return ObjectArrays.EMPTY_ARRAY;
|
||||||
Object[] obj = new Object[size()];
|
Object[] obj = new Object[size()];
|
||||||
for(int i = 0;i<size();i++)
|
for(int i = 0;i<size();i++)
|
||||||
obj[i] = KEY_TO_OBJ(data[i]);
|
obj[i] = KEY_TO_OBJ(data[i]);
|
||||||
@@ -497,347 +565,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||||
for(int i = 0;i<size();i++)
|
for(int i = 0;i<size();i++)
|
||||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||||
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
|
||||||
lastReturned = index;
|
|
||||||
return data[index++];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPrevious() {
|
|
||||||
return index > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE PREVIOUS() {
|
|
||||||
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 {
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
@@ -853,6 +584,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = index;
|
lastReturned = index;
|
||||||
return data[index++];
|
return data[index++];
|
||||||
}
|
}
|
||||||
@@ -864,8 +596,9 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
lastReturned = index;
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return data[index--];
|
--index;
|
||||||
|
return data[(lastReturned = index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -880,11 +613,9 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
ARRAY_SET.this.remove(data[lastReturned]);
|
ARRAY_SET.this.remove(data[lastReturned]);
|
||||||
if(lastReturned < index)
|
if(lastReturned < index) index--;
|
||||||
index--;
|
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,8 +637,9 @@ 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);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,6 +648,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+118
-27
@@ -1,24 +1,30 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -32,7 +38,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* Extra to that there is a couple quality of life functions provided
|
* Extra to that there is a couple quality of life functions provided
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing keys array */
|
/** The Backing keys array */
|
||||||
protected transient KEY_TYPE[] keys;
|
protected transient KEY_TYPE[] keys;
|
||||||
@@ -188,7 +194,18 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
{
|
{
|
||||||
KEY_TYPE o = a[i];
|
KEY_TYPE o = a[i];
|
||||||
if(KEY_EQUALS_NULL(o)) {
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
if(!containsNull) size++;
|
if(!containsNull) {
|
||||||
|
size++;
|
||||||
|
if(prev != -1) {
|
||||||
|
newLinks[prev] ^= ((newLinks[prev] ^ (newSize & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
newLinks[newSize] ^= ((newLinks[newSize] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||||
|
prev = newSize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev = firstIndex = newSize;
|
||||||
|
newLinks[newSize] = -1L;
|
||||||
|
}
|
||||||
|
}
|
||||||
containsNull = true;
|
containsNull = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -197,7 +214,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
KEY_TYPE current = newKeys[pos];
|
KEY_TYPE current = newKeys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
if(KEY_EQUALS(current, o)) continue;
|
if(KEY_EQUALS(current, o)) continue;
|
||||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & mask)]))) {
|
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & newMask)]))) {
|
||||||
if(KEY_EQUALS(current, o)) {
|
if(KEY_EQUALS(current, o)) {
|
||||||
found = false;
|
found = false;
|
||||||
break;
|
break;
|
||||||
@@ -218,7 +235,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nullIndex = size;
|
nullIndex = newSize;
|
||||||
mask = newMask;
|
mask = newMask;
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
links = newLinks;
|
links = newLinks;
|
||||||
@@ -228,6 +245,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
|
||||||
@@ -244,7 +265,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return containsNull;
|
if(o == null) return containsNull;
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -303,6 +329,17 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
int count = 0;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
action.accept(count++, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -318,7 +355,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return true;
|
if(filter.test(keys[index])) return true;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -329,7 +366,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return false;
|
if(filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -340,18 +377,62 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
if(!filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
if(filter.test(keys[index])) return keys[index];
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
@@ -363,7 +444,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) result++;
|
if(filter.test(keys[index])) result++;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -393,18 +474,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() { throw new UnsupportedOperationException(); }
|
public void clear() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@@ -450,6 +519,30 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(next != -1 && result != amount) {
|
||||||
|
current = previous = next;
|
||||||
|
next = (int)(links[current]);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index+=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(previous != -1 && result != amount) {
|
||||||
|
current = next = previous;
|
||||||
|
previous = (int)(links[current] >> 32);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index-=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return next != -1;
|
return next != -1;
|
||||||
@@ -478,9 +571,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
current = previous;
|
current = next = previous;
|
||||||
previous = (int)(links[current] >> 32);
|
previous = (int)(links[current] >> 32);
|
||||||
next = current;
|
|
||||||
if(index >= 0) index--;
|
if(index >= 0) index--;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
@@ -488,9 +580,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
current = next;
|
current = previous = next;
|
||||||
next = (int)(links[current]);
|
next = (int)(links[current]);
|
||||||
previous = current;
|
|
||||||
if(index >= 0) index++;
|
if(index >= 0) index++;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-34
@@ -1,30 +1,34 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
#endif
|
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
@@ -35,7 +39,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -125,7 +129,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||||
*/
|
*/
|
||||||
public LINKED_CUSTOM_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
public LINKED_CUSTOM_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||||
this(length < 0 ? 0 : length, strategy);
|
this(length, strategy);
|
||||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||||
}
|
}
|
||||||
@@ -239,6 +243,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
}
|
}
|
||||||
containsNull = true;
|
containsNull = true;
|
||||||
onNodeAdded(nullIndex);
|
onNodeAdded(nullIndex);
|
||||||
|
moveToFirstIndex(nullIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||||
@@ -251,6 +256,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
}
|
}
|
||||||
keys[pos] = o;
|
keys[pos] = o;
|
||||||
onNodeAdded(pos);
|
onNodeAdded(pos);
|
||||||
|
moveToFirstIndex(pos);
|
||||||
}
|
}
|
||||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
return true;
|
return true;
|
||||||
@@ -284,7 +290,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToFirst(KEY_TYPE o) {
|
public boolean moveToFirst(KEY_TYPE o) {
|
||||||
if(strategy.equals(FIRST_KEY(), o)) return false;
|
if(isEmpty() || strategy.equals(FIRST_KEY(), o)) return false;
|
||||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToFirstIndex(nullIndex);
|
moveToFirstIndex(nullIndex);
|
||||||
@@ -306,7 +312,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToLast(KEY_TYPE o) {
|
public boolean moveToLast(KEY_TYPE o) {
|
||||||
if(strategy.equals(LAST_KEY(), o)) return false;
|
if(isEmpty() || strategy.equals(LAST_KEY(), o)) return false;
|
||||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToLastIndex(nullIndex);
|
moveToLastIndex(nullIndex);
|
||||||
@@ -372,8 +378,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
public KEY_TYPE POLL_FIRST_KEY() {
|
public KEY_TYPE POLL_FIRST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
int pos = firstIndex;
|
int pos = firstIndex;
|
||||||
firstIndex = (int)links[pos];
|
onNodeRemoved(pos);
|
||||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
|
||||||
KEY_TYPE result = keys[pos];
|
KEY_TYPE result = keys[pos];
|
||||||
size--;
|
size--;
|
||||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||||
@@ -395,8 +400,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
public KEY_TYPE POLL_LAST_KEY() {
|
public KEY_TYPE POLL_LAST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
int pos = lastIndex;
|
int pos = lastIndex;
|
||||||
lastIndex = (int)(links[pos] >>> 32);
|
onNodeRemoved(pos);
|
||||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
|
||||||
KEY_TYPE result = keys[pos];
|
KEY_TYPE result = keys[pos];
|
||||||
size--;
|
size--;
|
||||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||||
@@ -510,7 +514,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
@Override
|
@Override
|
||||||
public void clearAndTrim(int size) {
|
public void clearAndTrim(int size) {
|
||||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(request >= size) {
|
if(request >= nullIndex) {
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -534,6 +538,17 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
int count = 0;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
action.accept(count++, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -549,7 +564,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return true;
|
if(filter.test(keys[index])) return true;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -560,7 +575,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return false;
|
if(filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -571,18 +586,62 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
if(!filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
if(filter.test(keys[index])) return keys[index];
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
@@ -594,7 +653,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) result++;
|
if(filter.test(keys[index])) result++;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -626,18 +685,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int previous = -1;
|
int previous = -1;
|
||||||
int next = -1;
|
int next = -1;
|
||||||
@@ -685,6 +732,30 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
return previous != -1;
|
return previous != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(next != -1 && result != amount) {
|
||||||
|
current = previous = next;
|
||||||
|
next = (int)(links[current]);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index+=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(previous != -1 && result != amount) {
|
||||||
|
current = next = previous;
|
||||||
|
previous = (int)(links[current] >> 32);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index-=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int nextIndex() {
|
public int nextIndex() {
|
||||||
ensureIndexKnown();
|
ensureIndexKnown();
|
||||||
@@ -743,9 +814,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
current = previous;
|
current = next = previous;
|
||||||
previous = (int)(links[current] >> 32);
|
previous = (int)(links[current] >> 32);
|
||||||
next = current;
|
|
||||||
if(index >= 0) index--;
|
if(index >= 0) index--;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
@@ -753,9 +823,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
current = next;
|
current = previous = next;
|
||||||
next = (int)(links[current]);
|
next = (int)(links[current]);
|
||||||
previous = current;
|
|
||||||
if(index >= 0) index++;
|
if(index >= 0) index++;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-34
@@ -1,8 +1,5 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
import java.util.Comparator;
|
|
||||||
#endif
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -10,6 +7,10 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
#endif
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
@@ -18,11 +19,14 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -36,7 +40,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -112,7 +116,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||||
*/
|
*/
|
||||||
public LINKED_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor) {
|
public LINKED_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor) {
|
||||||
this(length < 0 ? 0 : length);
|
this(length);
|
||||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||||
}
|
}
|
||||||
@@ -210,6 +214,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
containsNull = true;
|
containsNull = true;
|
||||||
onNodeAdded(nullIndex);
|
onNodeAdded(nullIndex);
|
||||||
|
moveToFirstIndex(nullIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||||
@@ -222,6 +227,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
keys[pos] = o;
|
keys[pos] = o;
|
||||||
onNodeAdded(pos);
|
onNodeAdded(pos);
|
||||||
|
moveToFirstIndex(pos);
|
||||||
}
|
}
|
||||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
return true;
|
return true;
|
||||||
@@ -255,7 +261,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToFirst(KEY_TYPE o) {
|
public boolean moveToFirst(KEY_TYPE o) {
|
||||||
if(KEY_EQUALS(FIRST_KEY(), o)) return false;
|
if(isEmpty() || KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||||
if(KEY_EQUALS_NULL(o)) {
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToFirstIndex(nullIndex);
|
moveToFirstIndex(nullIndex);
|
||||||
@@ -277,7 +283,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToLast(KEY_TYPE o) {
|
public boolean moveToLast(KEY_TYPE o) {
|
||||||
if(KEY_EQUALS(LAST_KEY(), o)) return false;
|
if(isEmpty() || KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||||
if(KEY_EQUALS_NULL(o)) {
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToLastIndex(nullIndex);
|
moveToLastIndex(nullIndex);
|
||||||
@@ -343,8 +349,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE POLL_FIRST_KEY() {
|
public KEY_TYPE POLL_FIRST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
int pos = firstIndex;
|
int pos = firstIndex;
|
||||||
firstIndex = (int)links[pos];
|
onNodeRemoved(pos);
|
||||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
|
||||||
KEY_TYPE result = keys[pos];
|
KEY_TYPE result = keys[pos];
|
||||||
size--;
|
size--;
|
||||||
if(KEY_EQUALS_NULL(result)) {
|
if(KEY_EQUALS_NULL(result)) {
|
||||||
@@ -366,8 +371,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE POLL_LAST_KEY() {
|
public KEY_TYPE POLL_LAST_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
int pos = lastIndex;
|
int pos = lastIndex;
|
||||||
lastIndex = (int)(links[pos] >>> 32);
|
onNodeRemoved(pos);
|
||||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
|
||||||
KEY_TYPE result = keys[pos];
|
KEY_TYPE result = keys[pos];
|
||||||
size--;
|
size--;
|
||||||
if(KEY_EQUALS_NULL(result)) {
|
if(KEY_EQUALS_NULL(result)) {
|
||||||
@@ -389,6 +393,17 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
int count = 0;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
action.accept(count++, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -404,7 +419,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return true;
|
if(filter.test(keys[index])) return true;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -415,7 +430,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return false;
|
if(filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -426,18 +441,62 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
if(!filter.test(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) return keys[index];
|
if(filter.test(keys[index])) return keys[index];
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
@@ -449,7 +508,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1) {
|
while(index != -1) {
|
||||||
if(filter.TEST_VALUE(keys[index])) result++;
|
if(filter.test(keys[index])) result++;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -557,7 +616,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void clearAndTrim(int size) {
|
public void clearAndTrim(int size) {
|
||||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(request >= size) {
|
if(request >= nullIndex) {
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -597,18 +656,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int previous = -1;
|
int previous = -1;
|
||||||
int next = -1;
|
int next = -1;
|
||||||
@@ -646,6 +693,30 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(next != -1 && result != amount) {
|
||||||
|
current = previous = next;
|
||||||
|
next = (int)(links[current]);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index+=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
int result = 0;
|
||||||
|
while(previous != -1 && result != amount) {
|
||||||
|
current = next = previous;
|
||||||
|
previous = (int)(links[current] >> 32);
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
if(index >= 0) index-=result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return next != -1;
|
return next != -1;
|
||||||
@@ -714,9 +785,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
current = previous;
|
current = next = previous;
|
||||||
previous = (int)(links[current] >> 32);
|
previous = (int)(links[current] >> 32);
|
||||||
next = current;
|
|
||||||
if(index >= 0) index--;
|
if(index >= 0) index--;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
@@ -724,9 +794,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
current = next;
|
current = previous = next;
|
||||||
next = (int)(links[current]);
|
next = (int)(links[current]);
|
||||||
previous = current;
|
|
||||||
if(index >= 0) index++;
|
if(index >= 0) index++;
|
||||||
return keys[current];
|
return keys[current];
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-2
@@ -4,6 +4,9 @@ import java.util.NavigableSet;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
#if SETS_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +121,30 @@ 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 SETS_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is Synchronized
|
||||||
|
* @return a new NavigableSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new NavigableSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is unmodifiable
|
||||||
|
* @return a new NavigableSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
@@ -146,10 +173,10 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
|||||||
default CLASS_TYPE last() { return SORTED_SET.super.last(); }
|
default CLASS_TYPE last() { return SORTED_SET.super.last(); }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE pollFirst() { return KEY_TO_OBJ(POLL_FIRST_KEY()); }
|
public default CLASS_TYPE pollFirst() { return isEmpty() ? null : KEY_TO_OBJ(POLL_FIRST_KEY()); }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE pollLast() { return KEY_TO_OBJ(POLL_LAST_KEY()); }
|
public default CLASS_TYPE pollLast() { return isEmpty() ? null : KEY_TO_OBJ(POLL_LAST_KEY()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
+125
-25
@@ -8,18 +8,24 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
#endif
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
#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;
|
||||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
|
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
@@ -275,6 +281,30 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||||
|
if(containsNull) return EMPTY_KEY_VALUE;
|
||||||
|
containsNull = true;
|
||||||
|
onNodeAdded(nullIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||||
|
KEY_TYPE current = keys[pos];
|
||||||
|
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
||||||
|
if(strategy.equals(current, o)) return current;
|
||||||
|
while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE))
|
||||||
|
if(strategy.equals(current, o)) return current;
|
||||||
|
}
|
||||||
|
keys[pos] = o;
|
||||||
|
onNodeAdded(pos);
|
||||||
|
}
|
||||||
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
@@ -347,10 +377,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(int size) {
|
public boolean trim(int size) {
|
||||||
int newSize = HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(newSize >= nullIndex || size >= Math.min((int)Math.ceil(newSize * loadFactor), newSize - 1)) return false;
|
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||||
try {
|
try {
|
||||||
rehash(newSize);
|
rehash(request);
|
||||||
}
|
}
|
||||||
catch(OutOfMemoryError e) { return false; }
|
catch(OutOfMemoryError e) { return false; }
|
||||||
return true;
|
return true;
|
||||||
@@ -359,7 +389,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
public void clearAndTrim(int size) {
|
public void clearAndTrim(int size) {
|
||||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(request >= size) {
|
if(request >= nullIndex) {
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -477,6 +507,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
if(size() <= 0) return;
|
if(size() <= 0) return;
|
||||||
if(containsNull) action.accept(keys[nullIndex]);
|
if(containsNull) action.accept(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
@@ -484,6 +515,16 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
if(size() <= 0) return;
|
||||||
|
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||||
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, keys[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -498,9 +539,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET 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);
|
||||||
if(size() <= 0) return false;
|
if(size() <= 0) return false;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return true;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -509,9 +550,9 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET 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);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return false;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -520,20 +561,68 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET 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);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.TEST_VALUE(keys[i])) return false;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && !filter.test(keys[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return EMPTY_VALUE;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) return keys[i];
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) return keys[i];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
@@ -543,19 +632,21 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return 0;
|
if(size() <= 0) return 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
if(containsNull && filter.test(keys[nullIndex])) result++;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.TEST_VALUE(keys[i])) result++;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && filter.test(keys[i])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
KEY_TYPE[] wrapped = null;
|
||||||
|
int wrappedIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -567,7 +658,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
else {
|
else {
|
||||||
while(true) {
|
while(true) {
|
||||||
if(--pos < 0) {
|
if(--pos < 0) {
|
||||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||||
nextIndex = -pos - 1;
|
nextIndex = -pos - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -584,9 +675,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
KEY_TYPE value = wrapped[nextIndex];
|
||||||
nextIndex = Integer.MIN_VALUE;
|
nextIndex = Integer.MIN_VALUE;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -602,9 +694,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
containsNull = false;
|
containsNull = false;
|
||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
CUSTOM_HASH_SET.this.remove(wrapped[-returnedPos - 1]);
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
@@ -625,12 +718,19 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||||
startPos = ++startPos & mask;
|
startPos = ++startPos & mask;
|
||||||
}
|
}
|
||||||
if(startPos < last) {
|
if(startPos < last) addWrapper(keys[startPos]);
|
||||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
|
||||||
wrapped.add(keys[startPos]);
|
|
||||||
}
|
|
||||||
keys[last] = current;
|
keys[last] = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addWrapper(KEY_TYPE value) {
|
||||||
|
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||||
|
else if(wrappedIndex >= wrapped.length) {
|
||||||
|
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||||
|
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||||
|
wrapped = newArray;
|
||||||
|
}
|
||||||
|
wrapped[wrappedIndex++] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+134
-25
@@ -8,18 +8,24 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
#endif
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
#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;
|
||||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
import speiger.src.collections.utils.ITrimmable;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
@@ -233,6 +239,30 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
|
if(containsNull) return null;
|
||||||
|
containsNull = true;
|
||||||
|
onNodeAdded(nullIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||||
|
KEY_TYPE current = keys[pos];
|
||||||
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
|
if(KEY_EQUALS(current, o)) return current;
|
||||||
|
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
||||||
|
if(KEY_EQUALS(current, o)) return current;
|
||||||
|
}
|
||||||
|
keys[pos] = o;
|
||||||
|
onNodeAdded(pos);
|
||||||
|
}
|
||||||
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
@@ -250,7 +280,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return containsNull;
|
if(o == null) return containsNull;
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -263,7 +298,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return (containsNull ? removeNullIndex() : false);
|
if(o == null) return (containsNull ? removeNullIndex() : false);
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -304,10 +344,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(int size) {
|
public boolean trim(int size) {
|
||||||
int newSize = HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(newSize >= nullIndex || size >= Math.min((int)Math.ceil(newSize * loadFactor), newSize - 1)) return false;
|
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||||
try {
|
try {
|
||||||
rehash(newSize);
|
rehash(request);
|
||||||
}
|
}
|
||||||
catch(OutOfMemoryError e) { return false; }
|
catch(OutOfMemoryError e) { return false; }
|
||||||
return true;
|
return true;
|
||||||
@@ -316,7 +356,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
@Override
|
@Override
|
||||||
public void clearAndTrim(int size) {
|
public void clearAndTrim(int size) {
|
||||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||||
if(request >= size) {
|
if(request >= nullIndex) {
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -337,6 +377,16 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachIndexed(BI_FROM_INT_CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
if(size() <= 0) return;
|
||||||
|
if(containsNull) action.accept(0, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, keys[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -351,9 +401,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return false;
|
if(size() <= 0) return false;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return true;
|
if(containsNull && filter.test(keys[nullIndex])) return true;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return true;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -362,9 +412,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return false;
|
if(containsNull && filter.test(keys[nullIndex])) return false;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return false;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -373,20 +423,68 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
if(containsNull && !filter.TEST_VALUE(keys[nullIndex])) return false;
|
if(containsNull && !filter.test(keys[nullIndex])) return false;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.TEST_VALUE(keys[i])) return false;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && !filter.test(keys[i])) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return EMPTY_VALUE;
|
if(size() <= 0) return EMPTY_VALUE;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) return keys[nullIndex];
|
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) return keys[i];
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) return keys[i];
|
||||||
}
|
}
|
||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
@@ -396,9 +494,9 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return 0;
|
if(size() <= 0) return 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if(containsNull && filter.TEST_VALUE(keys[nullIndex])) result++;
|
if(containsNull && filter.test(keys[nullIndex])) result++;
|
||||||
for(int i = nullIndex-1;i>=0;i--) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.TEST_VALUE(keys[i])) result++;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && filter.test(keys[i])) result++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -509,10 +607,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
LIST KEY_GENERIC_TYPE wrapped = null;
|
KEY_TYPE[] wrapped = null;
|
||||||
|
int wrappedIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -525,7 +625,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
{
|
{
|
||||||
while(true) {
|
while(true) {
|
||||||
if(--pos < 0) {
|
if(--pos < 0) {
|
||||||
if(wrapped == null || wrapped.size() <= -pos - 1) break;
|
if(wrapped == null || wrappedIndex <= -pos - 1) break;
|
||||||
nextIndex = -pos - 1;
|
nextIndex = -pos - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -542,9 +642,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
KEY_TYPE value = wrapped[nextIndex];
|
||||||
nextIndex = Integer.MIN_VALUE;
|
nextIndex = Integer.MIN_VALUE;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -560,9 +661,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
containsNull = false;
|
containsNull = false;
|
||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
HASH_SET.this.remove(wrapped[-returnedPos - 1]);
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
@@ -583,12 +685,19 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
if(last <= startPos ? (last >= slot || slot > startPos) : (last >= slot && slot > startPos)) break;
|
||||||
startPos = ++startPos & mask;
|
startPos = ++startPos & mask;
|
||||||
}
|
}
|
||||||
if(startPos < last) {
|
if(startPos < last) addWrapper(keys[startPos]);
|
||||||
if(wrapped == null) wrapped = new ARRAY_LISTBRACES(2);
|
|
||||||
wrapped.add(keys[startPos]);
|
|
||||||
}
|
|
||||||
keys[last] = current;
|
keys[last] = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addWrapper(KEY_TYPE value) {
|
||||||
|
if(wrapped == null) wrapped = NEW_KEY_ARRAY(2);
|
||||||
|
else if(wrappedIndex >= wrapped.length) {
|
||||||
|
KEY_TYPE[] newArray = NEW_KEY_ARRAY(wrapped.length * 2);
|
||||||
|
System.arraycopy(wrapped, 0, newArray, 0, wrapped.length);
|
||||||
|
wrapped = newArray;
|
||||||
|
}
|
||||||
|
wrapped[wrappedIndex++] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
#if SETS_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Special Set Interface giving Access to some really usefull functions
|
||||||
|
* The Idea behind this interface is to allow access to functions that give control to the Order of elements.
|
||||||
|
* Since Linked implementations as examples can be reordered outside of the Insertion Order.
|
||||||
|
* This interface provides basic access to such functions while also providing some Sorted/NaivgableSet implementations that still fit into here.
|
||||||
|
*
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A customized add method that allows you to insert into the first index.
|
||||||
|
* @param o the element that should be inserted
|
||||||
|
* @return true if it was added
|
||||||
|
* @see java.util.Set#add(Object)
|
||||||
|
*/
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o);
|
||||||
|
/**
|
||||||
|
* A customized add method that allows you to insert into the last index.
|
||||||
|
* @param o the element that should be inserted
|
||||||
|
* @return true if it was added
|
||||||
|
* @see java.util.Set#add(Object)
|
||||||
|
*/
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key to the first index.
|
||||||
|
* @param o that should be moved to the first index
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToFirst(KEY_TYPE o);
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key to the last index.
|
||||||
|
* @param o that should be moved to the first last
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToLast(KEY_TYPE o);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type Specific Iterator starting from a given key
|
||||||
|
* @param fromElement the element the iterator should start from
|
||||||
|
* @return a iterator starting from the given element
|
||||||
|
* @throws java.util.NoSuchElementException if fromElement isn't found
|
||||||
|
*/
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first element in the set
|
||||||
|
* @return first element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE FIRST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the first element in the set
|
||||||
|
* @return first element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get the last element in the set
|
||||||
|
* @return last element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE LAST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the last element in the set
|
||||||
|
* @return last element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_LAST_KEY();
|
||||||
|
|
||||||
|
#if SETS_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is Synchronized
|
||||||
|
* @return a new OrderedSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new OrderedSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is unmodifiable
|
||||||
|
* @return a new OrderedSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+1733
-1401
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,12 @@ 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;
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
#if SETS_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Set class to reduce boxing/unboxing
|
* A Type Specific Set class to reduce boxing/unboxing
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -49,6 +53,40 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
|||||||
public default boolean remove(Object o) {
|
public default boolean remove(Object o) {
|
||||||
return COLLECTION.super.remove(o);
|
return COLLECTION.super.remove(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* A Helper method that allows to add a element or getting the already present implement.
|
||||||
|
* Allowing to make unique references reuseable.
|
||||||
|
* @param o the element to add
|
||||||
|
* @return either the inserted element or the present element.
|
||||||
|
*/
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if SETS_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is Synchronized
|
||||||
|
* @return a new Set that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new Set Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is unmodifiable
|
||||||
|
* @return a new Set Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
|
|||||||
+29
-35
@@ -9,50 +9,20 @@ 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;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||||
* with a couple extra methods that allow greater control over sets.
|
* with a couple extra methods that allow greater control over sets.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
|
* @note ORDERED_SET is only extended until 0.6.0 for Compat reasons.
|
||||||
|
* The supported classes already implement ORDERED_SET directly and will remove SORTED_SET implementations in favor of ORDERED_SET instead
|
||||||
*/
|
*/
|
||||||
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the first index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the last index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the first index.
|
|
||||||
* @param o that should be moved to the first index
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the last index.
|
|
||||||
* @param o that should be moved to the first last
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Comparator method
|
* A Type Specific Comparator method
|
||||||
* @return the type specific comparator
|
* @return the type specific comparator
|
||||||
@@ -73,6 +43,30 @@ 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 SETS_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is Synchronized
|
||||||
|
* @return a new SortedSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is unmodifiable
|
||||||
|
* @return a new SortedSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
|
|||||||
+1655
-1595
File diff suppressed because it is too large
Load Diff
+1043
File diff suppressed because it is too large
Load Diff
+1036
-393
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
|
||||||
|
|||||||
+587
-197
@@ -1,198 +1,588 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import java.util.Objects;
|
||||||
#if !TYPE_OBJECT
|
#if TYPE_BOOLEAN
|
||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
#else if TYPE_OBJECT
|
||||||
#endif
|
import java.util.Comparator;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import java.util.function.Consumer;
|
||||||
|
#if JDK_FUNCTION
|
||||||
/**
|
import java.util.function.PREDICATE;
|
||||||
* A Helper class for Iterables
|
#endif
|
||||||
*/
|
|
||||||
public class ITERABLES
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
{
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
/**
|
#if !TYPE_OBJECT
|
||||||
* A Helper function that maps a Java-Iterable into a new Type.
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
* @param iterable the iterable that should be mapped
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
* @param mapper the function that decides what the result turns into.
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
* @Type(T)
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
* @param <E> The return type.
|
#endif
|
||||||
* @return a iterable that is mapped to a new result
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
*/
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
#if !JDK_FUNCTION
|
||||||
return new MappedIterable<>(wrap(iterable), mapper);
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
}
|
#endif
|
||||||
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
/**
|
|
||||||
* A Helper function that maps a Iterable into a new Type.
|
/**
|
||||||
* @param iterable the iterable that should be mapped
|
* A Helper class for Iterables
|
||||||
* @param mapper the function that decides what the result turns into.
|
*/
|
||||||
* @Type(T)
|
public class ITERABLES
|
||||||
* @param <E> The return type.
|
{
|
||||||
* @return a iterable that is mapped to a new result
|
/**
|
||||||
*/
|
* A Helper function that maps a Java-Iterable into a new Type.
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
* @param iterable the iterable that should be mapped
|
||||||
return new MappedIterable<>(iterable, mapper);
|
* @param mapper the function that decides what the result turns into.
|
||||||
}
|
* @Type(T)
|
||||||
|
* @param <E> The return type.
|
||||||
/**
|
* @return a iterable that is mapped to a new result
|
||||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
*/
|
||||||
* @param iterable the iterable that should be flatMapped
|
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||||
* @param mapper the function that decides what the result turns into.
|
return new MappedIterable<>(wrap(iterable), mapper);
|
||||||
* @Type(T)
|
}
|
||||||
* @param <V> The return type supplier.
|
|
||||||
* @param <E> The return type.
|
/**
|
||||||
* @return a iterable that is flatMapped to a new result
|
* A Helper function that maps a Iterable into a new Type.
|
||||||
*/
|
* @param iterable the iterable that should be mapped
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
* @param mapper the function that decides what the result turns into.
|
||||||
return new FlatMappedIterable<>(wrap(iterable), mapper);
|
* @Type(T)
|
||||||
}
|
* @param <E> The return type.
|
||||||
|
* @return a iterable that is mapped to a new result
|
||||||
/**
|
*/
|
||||||
* A Helper function that flatMaps a Iterable into a new Type.
|
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||||
* @param iterable the iterable that should be flatMapped
|
return new MappedIterable<>(iterable, mapper);
|
||||||
* @param mapper the function that decides what the result turns into.
|
}
|
||||||
* @Type(T)
|
|
||||||
* @param <V> The return type supplier.
|
/**
|
||||||
* @param <E> The return type.
|
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||||
* @return a iterable that is flatMapped to a new result
|
* @param iterable the iterable that should be flatMapped
|
||||||
*/
|
* @param mapper the function that decides what the result turns into.
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
* @Type(T)
|
||||||
return new FlatMappedIterable<>(iterable, mapper);
|
* @param <V> The return type supplier.
|
||||||
}
|
* @param <E> The return type.
|
||||||
|
* @return a iterable that is flatMapped to a new result
|
||||||
/**
|
*/
|
||||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
* @param iterable the iterable that should be flatMapped
|
return new FlatMappedIterable<>(wrap(iterable), mapper);
|
||||||
* @param mapper the function that decides what the result turns into.
|
}
|
||||||
* @Type(T)
|
|
||||||
* @param <E> The return type.
|
/**
|
||||||
* @return a iterable that is flatMapped to a new result
|
* A Helper function that flatMaps a Iterable into a new Type.
|
||||||
*/
|
* @param iterable the iterable that should be flatMapped
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
* @param mapper the function that decides what the result turns into.
|
||||||
return new FlatMappedArrayIterable<>(wrap(iterable), mapper);
|
* @Type(T)
|
||||||
}
|
* @param <V> The return type supplier.
|
||||||
|
* @param <E> The return type.
|
||||||
/**
|
* @return a iterable that is flatMapped to a new result
|
||||||
* A Helper function that flatMaps a Iterable into a new Type.
|
*/
|
||||||
* @param iterable the iterable that should be flatMapped
|
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
* @param mapper the function that decides what the result turns into.
|
return new FlatMappedIterable<>(iterable, mapper);
|
||||||
* @Type(T)
|
}
|
||||||
* @param <E> The return type.
|
|
||||||
* @return a iterable that is flatMapped to a new result
|
/**
|
||||||
*/
|
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
* @param iterable the iterable that should be flatMapped
|
||||||
return new FlatMappedArrayIterable<>(iterable, mapper);
|
* @param mapper the function that decides what the result turns into.
|
||||||
}
|
* @Type(T)
|
||||||
|
* @param <E> The return type.
|
||||||
/**
|
* @return a iterable that is flatMapped to a new result
|
||||||
* A Helper function that filters out all desired elements from a Java-Iterable
|
*/
|
||||||
* @param iterable that should be filtered.
|
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
* @param filter the filter that decides that should be let through
|
return new FlatMappedArrayIterable<>(wrap(iterable), mapper);
|
||||||
* @Type(T)
|
}
|
||||||
* @return a filtered iterable
|
|
||||||
*/
|
/**
|
||||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(Iterable<? extends CLASS_TYPE> iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
* A Helper function that flatMaps a Iterable into a new Type.
|
||||||
return new FilteredIterableBRACES(wrap(iterable), filter);
|
* @param iterable the iterable that should be flatMapped
|
||||||
}
|
* @param mapper the function that decides what the result turns into.
|
||||||
|
* @Type(T)
|
||||||
/**
|
* @param <E> The return type.
|
||||||
* A Helper function that filters out all desired elements
|
* @return a iterable that is flatMapped to a new result
|
||||||
* @param iterable that should be filtered.
|
*/
|
||||||
* @param filter the filter that decides that should be let through
|
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(ITERABLE KEY_GENERIC_TYPE iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
* @Type(T)
|
return new FlatMappedArrayIterable<>(iterable, mapper);
|
||||||
* @return a filtered iterable
|
}
|
||||||
*/
|
|
||||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
/**
|
||||||
return new FilteredIterableBRACES(iterable, filter);
|
* A Helper function that filters out all desired elements from a Java-Iterable
|
||||||
}
|
* @param iterable that should be filtered.
|
||||||
|
* @param filter the filter that decides that should be let through
|
||||||
/**
|
* @Type(T)
|
||||||
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
* @return a filtered iterable
|
||||||
* @param iterable that should be wrapped
|
*/
|
||||||
* @Type(T)
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(Iterable<? extends CLASS_TYPE> iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
* @return a type specific iterable
|
return new FilteredIterableBRACES(wrap(iterable), filter);
|
||||||
*/
|
}
|
||||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE wrap(Iterable<? extends CLASS_TYPE> iterable) {
|
|
||||||
return new WrappedIterableBRACES(iterable);
|
/**
|
||||||
}
|
* A Helper function that filters out all desired elements
|
||||||
|
* @param iterable that should be filtered.
|
||||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
* @param filter the filter that decides that should be let through
|
||||||
{
|
* @Type(T)
|
||||||
Iterable<? extends CLASS_TYPE> iterable;
|
* @return a filtered iterable
|
||||||
|
*/
|
||||||
public WrappedIterable(Iterable<? extends CLASS_TYPE> iterable) {
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
this.iterable = iterable;
|
return new FilteredIterableBRACES(iterable, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
/**
|
||||||
return ITERATORS.wrap(iterable.iterator());
|
* A Helper function that filters out all duplicated elements.
|
||||||
}
|
* @param iterable that should be distinct
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a distinct iterable
|
||||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
*/
|
||||||
{
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
return new DistinctIterableBRACES(iterable);
|
||||||
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper;
|
}
|
||||||
|
|
||||||
MappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper) {
|
/**
|
||||||
this.iterable = iterable;
|
* A Helper function that filters out all duplicated elements from a Java Iterable.
|
||||||
this.mapper = mapper;
|
* @param iterable that should be distinct
|
||||||
}
|
* @Type(T)
|
||||||
|
* @return a distinct iterable
|
||||||
public ObjectIterator<T> iterator() {
|
*/
|
||||||
return ITERATORS.map(iterable.iterator(), mapper);
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(Iterable<? extends CLASS_TYPE> iterable) {
|
||||||
}
|
return new DistinctIterableBRACES(wrap(iterable));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FlatMappedIterable KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterable<T>
|
/**
|
||||||
{
|
* A Helper function that repeats the Iterable a specific amount of times
|
||||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
* @param iterable that should be repeated
|
||||||
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, V> mapper;
|
* @param repeats the amount of times the iterable should be repeated
|
||||||
|
* @Type(T)
|
||||||
FlatMappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, V> mapper) {
|
* @return a repeating iterable
|
||||||
this.iterable = iterable;
|
*/
|
||||||
this.mapper = mapper;
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(ITERABLE KEY_GENERIC_TYPE iterable, int repeats) {
|
||||||
}
|
return new RepeatingIterableBRACES(iterable, repeats);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public ObjectIterator<T> iterator() {
|
/**
|
||||||
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
* A Helper function that repeats the Iterable a specific amount of times from a Java Iterable
|
||||||
}
|
* @param iterable that should be repeated
|
||||||
}
|
* @param repeats the amount of times the iterable should be repeated
|
||||||
|
* @Type(T)
|
||||||
private static class FlatMappedArrayIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
* @return a repeating iterable
|
||||||
{
|
*/
|
||||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(Iterable<? extends CLASS_TYPE> iterable, int repeats) {
|
||||||
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T[]> mapper;
|
return new RepeatingIterableBRACES(wrap(iterable), repeats);
|
||||||
|
}
|
||||||
FlatMappedArrayIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T[]> mapper) {
|
|
||||||
this.iterable = iterable;
|
/**
|
||||||
this.mapper = mapper;
|
* A Helper function that hard limits the Iterable to a specific size
|
||||||
}
|
* @param iterable that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
@Override
|
* @Type(T)
|
||||||
public ObjectIterator<T> iterator() {
|
* @return a limited iterable
|
||||||
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
*/
|
||||||
}
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||||
}
|
return new LimitedIterableBRACES(iterable, limit);
|
||||||
|
}
|
||||||
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
|
||||||
{
|
/**
|
||||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
* A Helper function that hard limits the Iterable to a specific size from a Java Iterable
|
||||||
PREDICATE KEY_GENERIC_TYPE filter;
|
* @param iterable that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
public FilteredIterable(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
* @Type(T)
|
||||||
this.iterable = iterable;
|
* @return a limited iterable
|
||||||
this.filter = filter;
|
*/
|
||||||
}
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(Iterable<? extends CLASS_TYPE> iterable, long limit) {
|
||||||
|
return new LimitedIterableBRACES(wrap(iterable), limit);
|
||||||
@Override
|
}
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
return ITERATORS.filter(iterable.iterator(), filter);
|
/**
|
||||||
}
|
* A Helper function that sorts the Iterable.
|
||||||
}
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||||
|
* @param iterable that should be sorted
|
||||||
|
* @param sorter that sorts the iterable. Can be null.
|
||||||
|
* @Type(T)
|
||||||
|
* @return a sorted iterable.
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return new SortedIterableBRACES(iterable, sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that sorts the Iterable from a Java Iterable
|
||||||
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||||
|
* @param iterable that should be sorted
|
||||||
|
* @param sorter that sorts the iterable. Can be null.
|
||||||
|
* @Type(T)
|
||||||
|
* @return a sorted iterable.
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(Iterable<? extends CLASS_TYPE> iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return new SortedIterableBRACES(wrap(iterable), sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that allows to preview the result of a Iterable.
|
||||||
|
* @param iterable that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterable returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIterableBRACES(iterable, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that allows to preview the result of a Iterable from a Java Iterable
|
||||||
|
* @param iterable that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterable returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(Iterable<? extends CLASS_TYPE> iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIterableBRACES(wrap(iterable), action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
||||||
|
* @param iterable that should be wrapped
|
||||||
|
* @Type(T)
|
||||||
|
* @return a type specific iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE wrap(Iterable<? extends CLASS_TYPE> iterable) {
|
||||||
|
return new WrappedIterableBRACES(iterable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
|
{
|
||||||
|
Iterable<? extends CLASS_TYPE> iterable;
|
||||||
|
|
||||||
|
public WrappedIterable(Iterable<? extends CLASS_TYPE> iterable) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.wrap(iterable.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
|
||||||
|
{
|
||||||
|
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||||
|
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper;
|
||||||
|
|
||||||
|
MappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectIterator<T> iterator() {
|
||||||
|
return ITERATORS.map(iterable.iterator(), mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(this);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> action.accept(mapper.apply(E)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FlatMappedIterable KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterable<T>
|
||||||
|
{
|
||||||
|
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||||
|
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, V> mapper;
|
||||||
|
|
||||||
|
FlatMappedIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, V> mapper) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIterator<T> iterator() {
|
||||||
|
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> mapper.apply(E).forEach(action));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FlatMappedArrayIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||||
|
{
|
||||||
|
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||||
|
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T[]> mapper;
|
||||||
|
|
||||||
|
FlatMappedArrayIterable(ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable, TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T[]> mapper) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIterator<T> iterator() {
|
||||||
|
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> {
|
||||||
|
T[] array = mapper.apply(E);
|
||||||
|
for(int i = 0,m=array.length;i<m;action.accept(array[i++]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RepeatingIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
int repeats;
|
||||||
|
|
||||||
|
public RepeatingIterable(ITERABLE KEY_GENERIC_TYPE iterable, int repeats) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.repeats = repeats;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.repeat(iterable.iterator(), repeats);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size() * (repeats+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||||
|
iterable.forEach(action.andThen(repeater::add));
|
||||||
|
for(int i = 0;i<repeats;i++)
|
||||||
|
repeater.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||||
|
iterable.forEach(T -> {action.accept(T); repeater.add(T);});
|
||||||
|
for(int i = 0;i<repeats;i++)
|
||||||
|
repeater.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
PREDICATE KEY_GENERIC_TYPE filter;
|
||||||
|
|
||||||
|
public FilteredIterable(ITERABLE KEY_GENERIC_TYPE iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.filter(iterable.iterator(), filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(T -> { if(!filter.test(T)) action.accept(T); } );
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(T -> { if(!filter.test(T)) action.accept(T); } );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
long limit;
|
||||||
|
|
||||||
|
public LimitedIterable(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.limit(iterable.iterator(), limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : (int)Math.min(prov.size(), limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
AtomicLong counter = new AtomicLong();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(counter.get() >= limit) return;
|
||||||
|
counter.incrementAndGet();
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
AtomicLong counter = new AtomicLong();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(counter.get() >= limit) return;
|
||||||
|
counter.incrementAndGet();
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||||
|
|
||||||
|
public SortedIterable(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.sorter = sorter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.sorted(iterable.iterator(), sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||||
|
iterable.forEach(wrapper::add);
|
||||||
|
wrapper.unstableSort(sorter);
|
||||||
|
wrapper.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||||
|
iterable.forEach(wrapper::add);
|
||||||
|
wrapper.unstableSort(sorter);
|
||||||
|
wrapper.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
|
||||||
|
public DistinctIterable(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.distinct(iterable.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
AtomicInteger result = new AtomicInteger();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(((result.get() & (T ? 2 : 1)) != 0)) return;
|
||||||
|
result.getAndAdd(T ? 2 : 1);
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
COLLECTION KEY_GENERIC_TYPE filtered = COLLECTIONS.distinctWrapper();
|
||||||
|
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
COLLECTION KEY_GENERIC_TYPE filtered = COLLECTIONS.distinctWrapper();
|
||||||
|
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
CONSUMER KEY_GENERIC_TYPE action;
|
||||||
|
|
||||||
|
public PeekIterable(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.peek(iterable.iterator(), action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(this.action.andThen(action));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(this.action.andThen(action));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1119
-837
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+13
-2
@@ -5,18 +5,25 @@ import java.util.Collection;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
#endif
|
#endif
|
||||||
|
#if JDK_FUNCTION
|
||||||
|
import java.util.function.PREDICATE;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
#if DEQUEUE_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
#if !JDK_FUNCTION
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +53,7 @@ public class PRIORITY_QUEUES
|
|||||||
return queue instanceof SynchronizedPriorityQueue ? (SynchronizedPriorityQueue KEY_GENERIC_TYPE)queue : new SynchronizedPriorityQueueBRACES(queue, mutex);
|
return queue instanceof SynchronizedPriorityQueue ? (SynchronizedPriorityQueue KEY_GENERIC_TYPE)queue : new SynchronizedPriorityQueueBRACES(queue, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEQUEUE_FEATURE
|
||||||
/**
|
/**
|
||||||
* Returns a synchronized PriorityDequeue instance based on the instance given.
|
* Returns a synchronized PriorityDequeue instance based on the instance given.
|
||||||
* @param dequeue that should be synchronized
|
* @param dequeue that should be synchronized
|
||||||
@@ -67,6 +75,7 @@ public class PRIORITY_QUEUES
|
|||||||
return dequeue instanceof SynchronizedPriorityDequeue ? (SynchronizedPriorityDequeue KEY_GENERIC_TYPE)dequeue : new SynchronizedPriorityDequeueBRACES(dequeue, mutex);
|
return dequeue instanceof SynchronizedPriorityDequeue ? (SynchronizedPriorityDequeue KEY_GENERIC_TYPE)dequeue : new SynchronizedPriorityDequeueBRACES(dequeue, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Wrapper class for synchronization
|
* Wrapper class for synchronization
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -117,7 +126,7 @@ public class PRIORITY_QUEUES
|
|||||||
@Override
|
@Override
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return queue.copy(); } }
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -134,6 +143,7 @@ public class PRIORITY_QUEUES
|
|||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEQUEUE_FEATURE
|
||||||
/**
|
/**
|
||||||
* Wrapper class for synchronization
|
* Wrapper class for synchronization
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -164,6 +174,7 @@ public class PRIORITY_QUEUES
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } }
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,31 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
#if TYPE_BOOLEAN
|
import java.util.NoSuchElementException;
|
||||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
import java.util.Set;
|
||||||
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
#if TYPE_OBJECT && SORTED_SET_FEATURE
|
||||||
import speiger.src.collections.booleans.sets.BooleanSet;
|
|
||||||
import speiger.src.collections.booleans.utils.BooleanCollections.EmptyCollection;
|
|
||||||
#else
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT && SORTED_SET_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
#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 ORDERED_SET_FEATURE
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
#endif
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.UnmodifiableCollection;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.UnmodifiableCollection;
|
||||||
import speiger.src.collections.utils.ITrimmable;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper class for sets
|
* A Helper class for sets
|
||||||
@@ -33,7 +35,7 @@ public class SETS
|
|||||||
/**
|
/**
|
||||||
* Empty Set Variable
|
* Empty Set Variable
|
||||||
*/
|
*/
|
||||||
public static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
private static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EmptySet getter
|
* EmptySet getter
|
||||||
@@ -48,7 +50,6 @@ public class SETS
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
|
||||||
/**
|
/**
|
||||||
* Creates a Synchronized set while preserving the ITrimmable interface
|
* Creates a Synchronized set while preserving the ITrimmable interface
|
||||||
* @param s the set that should be synchronized
|
* @param s the set that should be synchronized
|
||||||
@@ -72,6 +73,7 @@ public class SETS
|
|||||||
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex));
|
return s instanceof SynchronizedSet ? s : (s instanceof ITrimmable ? new SynchronizedTrimSetBRACES(s, mutex) : new SynchronizedSetBRACES(s, mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Synchronized SortedSet while preserving the ITrimmable interface
|
* Creates a Synchronized SortedSet while preserving the ITrimmable interface
|
||||||
* @param s the set that should be synchronized
|
* @param s the set that should be synchronized
|
||||||
@@ -95,6 +97,33 @@ public class SETS
|
|||||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ORDERED_SET_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
|
||||||
|
* @param s the set that should be synchronized
|
||||||
|
* @Type(T)
|
||||||
|
* @return a OrderedSet that is synchronized
|
||||||
|
* @note if the set is already synchronized then it will just self return it
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s) {
|
||||||
|
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s) : new SynchronizedOrderedSetBRACES(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
|
||||||
|
* @param s the set that should be synchronized
|
||||||
|
* @param mutex controller for access
|
||||||
|
* @Type(T)
|
||||||
|
* @return a OrderedSet that is synchronized
|
||||||
|
* @note if the set is already synchronized then it will just self return it
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||||
|
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s, mutex) : new SynchronizedOrderedSetBRACES(s, mutex));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
|
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
|
||||||
* @param s the set that should be synchronized
|
* @param s the set that should be synchronized
|
||||||
@@ -118,6 +147,7 @@ public class SETS
|
|||||||
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex));
|
return s instanceof SynchronizedNavigableSet ? s : (s instanceof ITrimmable ? new SynchronizedNavigableTrimSetBRACES(s, mutex) : new SynchronizedNavigableSetBRACES(s, mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Creates Unmodifyable Set wrapper
|
* Creates Unmodifyable Set wrapper
|
||||||
* @param s set that should be made unmodifiable
|
* @param s set that should be made unmodifiable
|
||||||
@@ -128,6 +158,7 @@ public class SETS
|
|||||||
return s instanceof UnmodifiableSet ? s : new UnmodifiableSetBRACES(s);
|
return s instanceof UnmodifiableSet ? s : new UnmodifiableSetBRACES(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates Unmodifyable SortedSet wrapper
|
* Creates Unmodifyable SortedSet wrapper
|
||||||
* @param s sortedSet that should be made unmodifiable
|
* @param s sortedSet that should be made unmodifiable
|
||||||
@@ -138,6 +169,20 @@ public class SETS
|
|||||||
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
|
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ORDERED_SET_FEATURE
|
||||||
|
/**
|
||||||
|
* Creates Unmodifyable OrderedSet wrapper
|
||||||
|
* @param s OrderedSet that should be made unmodifiable
|
||||||
|
* @Type(T)
|
||||||
|
* @return a UnmodifyableOrderedSet, if the set is already unmodifiable then it returns itself
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE unmodifiable(ORDERED_SET KEY_GENERIC_TYPE s) {
|
||||||
|
return s instanceof UnmodifiableOrderedSet ? s : new UnmodifiableOrderedSetBRACES(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
/**
|
/**
|
||||||
* Creates Unmodifyable NavigableSet wrapper
|
* Creates Unmodifyable NavigableSet wrapper
|
||||||
* @param s navigableSet that should be made unmodifiable
|
* @param s navigableSet that should be made unmodifiable
|
||||||
@@ -173,16 +218,19 @@ public class SETS
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#endif
|
||||||
@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() {
|
||||||
boolean next = true;
|
boolean next = true;
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() { return next = false; }
|
public boolean hasNext() { return next; }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!next) throw new IllegalStateException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
next = false;
|
next = false;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
@@ -200,12 +248,22 @@ public class SETS
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o == this) return true;
|
||||||
|
if(!(o instanceof Set)) return false;
|
||||||
|
return ((Set<?>)o).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if SORTED_SET_FEATURE
|
||||||
private static class UnmodifiableNavigableSet KEY_GENERIC_TYPE extends UnmodifiableSortedSet KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE
|
private static class UnmodifiableNavigableSet KEY_GENERIC_TYPE extends UnmodifiableSortedSet KEY_GENERIC_TYPE implements NAVIGABLE_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
NAVIGABLE_SET KEY_GENERIC_TYPE n;
|
NAVIGABLE_SET KEY_GENERIC_TYPE n;
|
||||||
@@ -218,25 +276,38 @@ public class SETS
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(KEY_TYPE o) { return n.contains(o); }
|
public boolean contains(KEY_TYPE o) { return n.contains(o); }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE lower(CLASS_TYPE e) { return n.lower(e); }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE floor(CLASS_TYPE e) { return n.floor(e); }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE ceiling(CLASS_TYPE e) { return n.ceiling(e); }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE higher(CLASS_TYPE e) { return n.higher(e); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) { return n.contains(o); }
|
public boolean contains(Object o) { return n.contains(o); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE lower(KEY_TYPE e) { return n.lower(e); }
|
public KEY_TYPE lower(KEY_TYPE e) { return n.lower(e); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE floor(KEY_TYPE e) { return n.floor(e); }
|
public KEY_TYPE floor(KEY_TYPE e) { return n.floor(e); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE ceiling(KEY_TYPE e) { return n.ceiling(e); }
|
public KEY_TYPE ceiling(KEY_TYPE e) { return n.ceiling(e); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { return n.higher(e); }
|
public KEY_TYPE higher(KEY_TYPE e) { return n.higher(e); }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@@ -251,33 +322,70 @@ public class SETS
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { return n.copy(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return SETS.unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return unmodifiable(n.headSet(toElement, inclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return SETS.unmodifiable(n.headSet(toElement, inclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return unmodifiable(n.tailSet(fromElement, inclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return SETS.unmodifiable(n.tailSet(fromElement, inclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return unmodifiable(n.descendingSet()); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return SETS.unmodifiable(n.descendingSet()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(n.subSet(fromElement, toElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(n.subSet(fromElement, toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(n.headSet(toElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(n.headSet(toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(n.tailSet(fromElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ORDERED_SET_FEATURE
|
||||||
|
private static class UnmodifiableOrderedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE s;
|
||||||
|
UnmodifiableOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c)
|
||||||
|
{
|
||||||
|
super(c);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
SORTED_SET KEY_GENERIC_TYPE s;
|
SORTED_SET KEY_GENERIC_TYPE s;
|
||||||
@@ -287,52 +395,31 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(s.headSet(toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(s.tailSet(fromElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Unmodifyable Set wrapper that helps is used with unmodifyableSet function
|
* Unmodifyable Set wrapper that helps is used with unmodifyableSet function
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -347,8 +434,13 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@@ -356,6 +448,7 @@ public class SETS
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SORTED_SET_FEATURE
|
||||||
private static class SynchronizedNavigableTrimSet KEY_GENERIC_TYPE extends SynchronizedNavigableSet KEY_GENERIC_TYPE implements ITrimmable
|
private static class SynchronizedNavigableTrimSet KEY_GENERIC_TYPE extends SynchronizedNavigableSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
{
|
{
|
||||||
ITrimmable trim;
|
ITrimmable trim;
|
||||||
@@ -390,7 +483,7 @@ public class SETS
|
|||||||
super(c, mutex);
|
super(c, mutex);
|
||||||
n = c;
|
n = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) { synchronized(mutex) { return n.contains(o); } }
|
public boolean contains(Object o) { synchronized(mutex) { return n.contains(o); } }
|
||||||
@@ -398,27 +491,33 @@ public class SETS
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return n.contains(o); } }
|
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return n.contains(o); } }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE lower(CLASS_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE floor(CLASS_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE ceiling(CLASS_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CLASS_TYPE higher(CLASS_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE lower(KEY_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
public KEY_TYPE lower(KEY_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE floor(KEY_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
public KEY_TYPE floor(KEY_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE ceiling(KEY_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
public KEY_TYPE ceiling(KEY_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
public KEY_TYPE higher(KEY_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMaxValue(e); } }
|
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMaxValue(e); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE getDefaultMaxValue() { synchronized(mutex) { return n.getDefaultMaxValue(); } }
|
public KEY_TYPE getDefaultMaxValue() { synchronized(mutex) { return n.getDefaultMaxValue(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMinValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMinValue(e); } }
|
public void setDefaultMinValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMinValue(e); } }
|
||||||
|
|
||||||
@@ -427,31 +526,31 @@ public class SETS
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return n.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.headSet(toElement, inclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement, inclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return synchronize(n.descendingSet(), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return SETS.synchronize(n.descendingSet(), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.subSet(fromElement, toElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.headSet(toElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(n.tailSet(fromElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement), mutex); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
@@ -488,53 +587,93 @@ public class SETS
|
|||||||
super(c, mutex);
|
super(c, mutex);
|
||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.headSet(toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(s.tailSet(fromElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if ORDERED_SET_FEATURE
|
||||||
|
private static class SynchronizedOrderedTrimSet KEY_GENERIC_TYPE extends SynchronizedOrderedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
|
{
|
||||||
|
ITrimmable trim;
|
||||||
|
|
||||||
|
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c) {
|
||||||
|
super(c);
|
||||||
|
trim = (ITrimmable)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
|
super(c, mutex);
|
||||||
|
trim = (ITrimmable)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAndTrim(int size) { synchronized(mutex) { trim.clearAndTrim(size); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SynchronizedOrderedSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE s;
|
||||||
|
|
||||||
|
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c) {
|
||||||
|
super(c);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
|
super(c, mutex);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
private static class SynchronizedTrimSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ITrimmable
|
private static class SynchronizedTrimSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
{
|
{
|
||||||
ITrimmable trim;
|
ITrimmable trim;
|
||||||
@@ -558,31 +697,29 @@ public class SETS
|
|||||||
|
|
||||||
private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
#if !TYPE_OBJECT
|
|
||||||
SET KEY_GENERIC_TYPE s;
|
SET KEY_GENERIC_TYPE s;
|
||||||
#endif
|
|
||||||
|
|
||||||
SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
||||||
super(c);
|
super(c);
|
||||||
#if !TYPE_OBJECT
|
|
||||||
s = c;
|
s = c;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
super(c, mutex);
|
super(c, mutex);
|
||||||
#if !TYPE_OBJECT
|
|
||||||
s = c;
|
s = c;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE addOrGet(KEY_TYPE o) { synchronized(mutex) { return s.addOrGet(o); } }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
public boolean remove(KEY_TYPE o) { synchronized(mutex) { return s.remove(o); } }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -1,6 +1,7 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Spliterator;
|
import java.util.Spliterator;
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||||
@@ -329,7 +330,11 @@ public class SPLIT_ITERATORS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() { return array[index++]; }
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return array[index++];
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() { return index < fence; }
|
public boolean hasNext() { return index < fence; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Strategy class that allows to give control hashcode generation and equals comparason for maps
|
* A Type Specific Strategy class that allows to give control hashcode generation and equals comparason for maps
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -19,6 +21,17 @@ public interface STRATEGY KEY_GENERIC_TYPE
|
|||||||
public static GENERIC_KEY_BRACES STRATEGY KEY_GENERIC_TYPE identityStrategy() { return (STRATEGY<KEY_TYPE>)IDENTITY; }
|
public static GENERIC_KEY_BRACES STRATEGY KEY_GENERIC_TYPE identityStrategy() { return (STRATEGY<KEY_TYPE>)IDENTITY; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* Normal Strategy
|
||||||
|
*/
|
||||||
|
public static final STRATEGY NO_GENERIC_TYPE NORMAL = new NormalStrategyBRACES();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Type(T)
|
||||||
|
* @return a Normal Strategy that is behaving exactly like the normal Hash Strategy in the Hash Collections
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES STRATEGY KEY_GENERIC_TYPE normalStrategy() { return (STRATEGY KEY_GENERIC_TYPE)NORMAL; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type Specific HashCode function
|
* Type Specific HashCode function
|
||||||
* @param o the element that the hashcode is requested for (if object may be null)
|
* @param o the element that the hashcode is requested for (if object may be null)
|
||||||
@@ -47,5 +60,18 @@ public interface STRATEGY KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(KEY_TYPE key, KEY_TYPE value) { return key == value; }
|
public boolean equals(KEY_TYPE key, KEY_TYPE value) { return key == value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* A Strategy that simulates the normal Hash Collection Behavior if you want to use Hash Control Collections to replace normal ones.
|
||||||
|
* Only real reason to do that is you have to use this and want to get rid of implementations.
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public static class NormalStrategy KEY_GENERIC_TYPE implements STRATEGY KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int hashCode(KEY_TYPE o) { return KEY_TO_HASH(o); }
|
||||||
|
@Override
|
||||||
|
public boolean equals(KEY_TYPE key, KEY_TYPE value) { return EQUALS_KEY_TYPE(key, value); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+1179
-921
File diff suppressed because it is too large
Load Diff
+93
@@ -0,0 +1,93 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.CollectionTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.testers.CollectionRemoveIfTester;
|
||||||
|
|
||||||
|
import speiger.src.testers.base.tests.collection.JavaCollectionRemoveIfTester;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddAllArrayTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionClearTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsAnyTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionCopyTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionEqualsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionForEachTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRemoveAllTester;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRemoveIfTester;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionStreamTester;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRetainAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionToArrayTester;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableCountTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableDistinctTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableFilterTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableFindFirstTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableLimitTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableMapTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableMatchesTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterablePeekTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableReduceTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableRepeatTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableSortedTester;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE extends CollectionTestSuiteBuilder<CLASS_TYPE> {
|
||||||
|
public static GENERIC_KEY_BRACES COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE) new COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
|
||||||
|
testers.remove(CollectionRemoveIfTester.class);
|
||||||
|
testers.add(JavaCollectionRemoveIfTester.class);
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
testers.add(FILE_KEY_TYPEIterableMapTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableFilterTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableDistinctTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableLimitTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableSortedTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableMatchesTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterablePeekTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableReduceTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableRepeatTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableCountTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEIterableFindFirstTester.class);
|
||||||
|
#endif
|
||||||
|
testers.add(FILE_KEY_TYPECollectionAddAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionAddAllArrayTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionAddTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionClearTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionContainsAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionContainsAnyTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionContainsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionCopyTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionEqualsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionForEachTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionIteratorTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionRemoveAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPECollectionRetainAllTester.class);
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
testers.add(FILE_KEY_TYPECollectionRemoveIfTester.class);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
testers.add(FILE_KEY_TYPECollectionStreamTester.class);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
testers.add(FILE_KEY_TYPECollectionToArrayTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueDequeueTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueEnqueueTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueLastTester;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE extends QUEUE_TEST_BUILDER KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public static GENERIC_KEY_BRACES DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE builder) {
|
||||||
|
return (DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE)new DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> tester = super.getTesters();
|
||||||
|
tester.add(FILE_KEY_TYPEDequeueDequeueTester.class);
|
||||||
|
tester.add(FILE_KEY_TYPEDequeueEnqueueTester.class);
|
||||||
|
tester.add(FILE_KEY_TYPEDequeueLastTester.class);
|
||||||
|
return tester;
|
||||||
|
}
|
||||||
|
}
|
||||||
+384
@@ -0,0 +1,384 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS;
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.ListTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.TestListGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
import com.google.common.collect.testing.testers.CollectionSerializationEqualTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListAddAllAtIndexTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListAddAllTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListAddAtIndexTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListAddTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListCreationTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListEqualsTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListGetTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListHashCodeTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListIndexOfTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListLastIndexOfTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListRemoveAllTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListRemoveAtIndexTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListRemoveTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListReplaceAllTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListRetainAllTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListSetTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListSubListTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListToArrayTester;
|
||||||
|
import com.google.common.testing.SerializableTester;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.testers.base.tests.list.JavaListListIteratorTester;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_LIST_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAbsentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllArrayAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllListAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListCreationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListEqualsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListExtractElementsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListGetElementsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListGetTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListIndexOfTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListLastIndexOfTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListListIteratorTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListPresentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveElementsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveTester;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSortTester;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListFillBufferTester;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListReplaceAllTester;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRetainAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSetTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSubListTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSwapRemoveAtIndexTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSwapRemoveTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListToArrayTester;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class LIST_TEST_BUILDER KEY_GENERIC_TYPE extends COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
KEY_TYPE[] prefixes;
|
||||||
|
KEY_TYPE[] suffixes;
|
||||||
|
#else
|
||||||
|
KEY_TYPE[] prefixes = createPrefixes();
|
||||||
|
KEY_TYPE[] suffixes = createSuffixes();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static GENERIC_KEY_BRACES LIST_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_LIST_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (LIST_TEST_BUILDER KEY_GENERIC_TYPE) new LIST_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LIST_TEST_BUILDER KEY_GENERIC_TYPE setPrefixes(KEY_TYPE[] prefixes) {
|
||||||
|
this.prefixes = prefixes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LIST_TEST_BUILDER KEY_GENERIC_TYPE setSuffixes(KEY_TYPE[] suffixes) {
|
||||||
|
this.suffixes = suffixes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
public KEY_TYPE[] createPrefixes() {
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
return new KEY_TYPE[]{false, false, false};
|
||||||
|
#else if TYPE_BYTE
|
||||||
|
return new KEY_TYPE[]{(byte)-3, (byte)-2, (byte)-1};
|
||||||
|
#else if TYPE_SHORT
|
||||||
|
return new KEY_TYPE[]{(short)-3, (short)-2, (short)-1};
|
||||||
|
#else if TYPE_CHAR
|
||||||
|
return new KEY_TYPE[]{'^', '_', '`'};
|
||||||
|
#else
|
||||||
|
return new KEY_TYPE[]{-3, -2, -1};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE[] createSuffixes() {
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
return new KEY_TYPE[]{true, true, true};
|
||||||
|
#else if TYPE_BYTE
|
||||||
|
return new KEY_TYPE[]{(byte)5, (byte)6, (byte)7};
|
||||||
|
#else if TYPE_SHORT
|
||||||
|
return new KEY_TYPE[]{(short)5, (short)6, (short)7};
|
||||||
|
#else if TYPE_CHAR
|
||||||
|
return new KEY_TYPE[]{'f', 'g', 'h'};
|
||||||
|
#else
|
||||||
|
return new KEY_TYPE[]{5, 6, 7};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
|
||||||
|
|
||||||
|
testers.add(CollectionSerializationEqualTester.class);
|
||||||
|
testers.add(ListAddAllAtIndexTester.class);
|
||||||
|
testers.add(ListAddAllTester.class);
|
||||||
|
testers.add(ListAddAtIndexTester.class);
|
||||||
|
testers.add(ListAddTester.class);
|
||||||
|
testers.add(ListCreationTester.class);
|
||||||
|
testers.add(ListEqualsTester.class);
|
||||||
|
testers.add(ListGetTester.class);
|
||||||
|
testers.add(ListHashCodeTester.class);
|
||||||
|
testers.add(ListIndexOfTester.class);
|
||||||
|
testers.add(ListLastIndexOfTester.class);
|
||||||
|
testers.add(JavaListListIteratorTester.class);
|
||||||
|
testers.add(ListRemoveAllTester.class);
|
||||||
|
testers.add(ListRemoveAtIndexTester.class);
|
||||||
|
testers.add(ListRemoveTester.class);
|
||||||
|
testers.add(ListReplaceAllTester.class);
|
||||||
|
testers.add(ListRetainAllTester.class);
|
||||||
|
testers.add(ListSetTester.class);
|
||||||
|
testers.add(ListSubListTester.class);
|
||||||
|
testers.add(ListToArrayTester.class);
|
||||||
|
|
||||||
|
testers.add(FILE_KEY_TYPEListAddAllAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAddAllListAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAddAllArrayAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAddAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAddAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAddTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListAbsentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListPresentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListCreationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListEqualsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListGetTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListGetElementsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListExtractElementsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListIndexOfTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListLastIndexOfTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListListIteratorTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListRemoveAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListRemoveAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListRemoveTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListRemoveElementsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListSwapRemoveAtIndexTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListSwapRemoveTester.class);
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
testers.add(FILE_KEY_TYPEListSortTester.class);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
testers.add(FILE_KEY_TYPEListFillBufferTester.class);
|
||||||
|
#endif
|
||||||
|
testers.add(FILE_KEY_TYPEListReplaceAllTester.class);
|
||||||
|
#endif
|
||||||
|
testers.add(FILE_KEY_TYPEListRetainAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListSetTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListSubListTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEListToArrayTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite createTestSuite() {
|
||||||
|
#ignore
|
||||||
|
withFeatures(KNOWN_ORDER);
|
||||||
|
#endignore
|
||||||
|
return super.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder));
|
||||||
|
#ignore
|
||||||
|
if (parentBuilder.getFeatures().contains(SERIALIZABLE)) {
|
||||||
|
#endignore
|
||||||
|
derivedSuites.add(ListTestSuiteBuilder.using(new ReserializedListGenerator<CLASS_TYPE>(parentBuilder.getSubjectGenerator()))
|
||||||
|
.named(getName() + " reserialized")
|
||||||
|
.withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
}
|
||||||
|
#ignore
|
||||||
|
if(!parentBuilder.getFeatures().contains(CollectionFeature.SUBSET_VIEW)) {
|
||||||
|
#endignore
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
if(prefixes != null) {
|
||||||
|
derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), prefixes, null))
|
||||||
|
.named(getName() + " subSet_prefix")
|
||||||
|
.withFeatures(computeSubListFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
}
|
||||||
|
if(suffixes != null) {
|
||||||
|
derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), null, suffixes))
|
||||||
|
.named(getName() + " subSet_suffixes")
|
||||||
|
.withFeatures(computeSubListFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
}
|
||||||
|
if(prefixes != null && suffixes != null) {
|
||||||
|
derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), prefixes, suffixes))
|
||||||
|
.named(getName() + " subSet")
|
||||||
|
.withFeatures(computeSubListFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class SubListListGenerator KEY_GENERIC_TYPE implements TEST_LIST_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
TEST_LIST_GENERATOR KEY_GENERIC_TYPE generator;
|
||||||
|
KEY_TYPE[] prefix;
|
||||||
|
KEY_TYPE[] suffix;
|
||||||
|
|
||||||
|
public SubListListGenerator(OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE> gen, KEY_TYPE[] prefix, KEY_TYPE[] suffix) {
|
||||||
|
generator = (TEST_LIST_GENERATOR KEY_GENERIC_TYPE)gen.getInnerGenerator();
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.suffix = suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SampleElements<CLASS_TYPE> samples() {
|
||||||
|
return generator.samples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE[] createArray(int length) {
|
||||||
|
return generator.createArray(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
return generator.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
return generator.getSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
return generator.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length);
|
||||||
|
int i = 0;
|
||||||
|
for (Object e : elements) {
|
||||||
|
array[i++] = CLASS_TO_KEY(e);
|
||||||
|
}
|
||||||
|
return create(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
int length = getLength(prefix);
|
||||||
|
return generator.create(merge(elements)).subList(length, length+elements.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length);
|
||||||
|
int i = 0;
|
||||||
|
for (Object e : elements) {
|
||||||
|
array[i++] = CLASS_TO_KEY(e);
|
||||||
|
}
|
||||||
|
int length = getLength(prefix);
|
||||||
|
return generator.create(merge(array)).subList(length, length+elements.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
private int getLength(KEY_TYPE[] keys) {
|
||||||
|
return keys == null ? 0 : keys.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private KEY_TYPE[] merge(KEY_TYPE[] input) {
|
||||||
|
int prefixLength = getLength(prefix);
|
||||||
|
int suffixLength = getLength(suffix);
|
||||||
|
KEY_TYPE[] result = NEW_KEY_ARRAY(input.length+prefixLength+suffixLength);
|
||||||
|
if(prefixLength != 0) System.arraycopy(prefix, 0, result, 0, prefixLength);
|
||||||
|
System.arraycopy(input, 0, result, prefixLength, input.length);
|
||||||
|
if(suffixLength != 0) System.arraycopy(suffix, 0, result, prefixLength+input.length, suffixLength);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ReserializedListGenerator<E> implements TestListGenerator<E> {
|
||||||
|
final OneSizeTestContainerGenerator<Collection<E>, E> gen;
|
||||||
|
|
||||||
|
private ReserializedListGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
|
||||||
|
this.gen = gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SampleElements<E> samples() {
|
||||||
|
return gen.samples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<E> create(Object... elements) {
|
||||||
|
return (List<E>) SerializableTester.reserialize(gen.create(elements));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public E[] createArray(int length) {
|
||||||
|
return gen.createArray(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<E> order(List<E> insertionOrder) {
|
||||||
|
return gen.order(insertionOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
private static Set<Feature<?>> computeSubListFeatures(Set<Feature<?>> features) {
|
||||||
|
Set<Feature<?>> derivedFeatures = new HashSet<>(features);
|
||||||
|
#ignore
|
||||||
|
derivedFeatures.add(CollectionFeature.SUBSET_VIEW);
|
||||||
|
derivedFeatures.remove(SpecialFeature.COPYING);
|
||||||
|
derivedFeatures.remove(SpecialFeature.CHILDREN_COPY);
|
||||||
|
#endignore
|
||||||
|
return derivedFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
private static Set<Feature<?>> computeReserializedCollectionFeatures(Set<Feature<?>> features) {
|
||||||
|
Set<Feature<?>> derivedFeatures = new HashSet<>(features);
|
||||||
|
#ignore
|
||||||
|
derivedFeatures.remove(SERIALIZABLE);
|
||||||
|
derivedFeatures.remove(SERIALIZABLE_INCLUDING_VIEWS);
|
||||||
|
#endignore
|
||||||
|
return derivedFeatures;
|
||||||
|
}
|
||||||
|
}
|
||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.DESCENDING_VIEW;
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.SUBSET_VIEW;
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.DerivedCollectionGenerators.Bound;
|
||||||
|
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
import com.google.common.collect.testing.testers.NavigableSetNavigationTester;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.impl.SUB_SORTED_SET_CLASS_GENERATOR.SUB_NAVIGABLE_SET_CLASS_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPENavigableSetNavigationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||||
|
public static GENERIC_KEY_BRACES NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE) new NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
|
||||||
|
testers.add(NavigableSetNavigationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPENavigableSetNavigationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder));
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
if (!parentBuilder.getFeatures().contains(SUBSET_VIEW)) {
|
||||||
|
#endignore
|
||||||
|
// Other combinations are inherited from SortedSetTestSuiteBuilder.
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.INCLUSIVE));
|
||||||
|
}
|
||||||
|
#ignore
|
||||||
|
if (!parentBuilder.getFeatures().contains(DESCENDING_VIEW)) {
|
||||||
|
#endignore
|
||||||
|
derivedSuites.add(createDescendingSuite(parentBuilder));
|
||||||
|
}
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE newBuilderUsing(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
return NAVIGABLE_SET_TEST_BUILDER.using(new SUB_NAVIGABLE_SET_CLASS_GENERATORBRACES(delegate, to, from));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TestSuite createDescendingSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||||
|
TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||||
|
|
||||||
|
List<Feature<?>> features = new ArrayList<>();
|
||||||
|
#ignore
|
||||||
|
features.add(DESCENDING_VIEW);
|
||||||
|
features.addAll(parentBuilder.getFeatures());
|
||||||
|
features.remove(SpecialFeature.COPYING);
|
||||||
|
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
return NAVIGABLE_SET_TEST_BUILDER.using(new TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SampleElements<CLASS_TYPE> samples() {
|
||||||
|
return delegate.samples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
return delegate.getSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
delegate.order(insertionOrder).forEach(list::add);
|
||||||
|
LISTS.reverse(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
for(CLASS_TYPE entry : delegate.order(insertionOrder))
|
||||||
|
{
|
||||||
|
list.add(OBJ_TO_KEY(entry));
|
||||||
|
}
|
||||||
|
LISTS.reverse(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return delegate.aboveSamplesGreater(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return delegate.aboveSamplesLesser(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return delegate.belowSamplesGreater(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return delegate.belowSamplesLesser(); }
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return delegate.create(elements).descendingSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
return delegate.create(elements).descendingSet();
|
||||||
|
}
|
||||||
|
}).named(parentBuilder.getName() + " descending").withFeatures(features)
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||||
|
}
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetMoveTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetIterationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetNavigationTester;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE) new ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
|
||||||
|
testers.add(FILE_KEY_TYPEOrderedSetNavigationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEOrderedSetMoveTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEOrderedSetIterationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite createTestSuite() {
|
||||||
|
#ignore
|
||||||
|
withFeatures(CollectionFeature.KNOWN_ORDER);
|
||||||
|
#endignore
|
||||||
|
return super.createTestSuite();
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.PerCollectionSizeTestSuiteBuilder;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueDequeueTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueEnqueueTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueFirstTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueRemoveTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueCountTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueDistinctTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueFilterTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueFindFirstTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueLimitTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueMapTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueMatchesTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueuePeekTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueForEachTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueReduceTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueSortedTester;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class QUEUE_TEST_BUILDER KEY_GENERIC_TYPE extends PerCollectionSizeTestSuiteBuilder<QUEUE_TEST_BUILDER KEY_GENERIC_TYPE, TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE, PRIORITY_QUEUE KEY_GENERIC_TYPE, CLASS_TYPE>
|
||||||
|
{
|
||||||
|
public static GENERIC_KEY_BRACES QUEUE_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE builder) {
|
||||||
|
return new QUEUE_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters()
|
||||||
|
{
|
||||||
|
List<Class<? extends AbstractTester>> testers = new ArrayList<>();
|
||||||
|
testers.add(FILE_KEY_TYPEQueueEnqueueTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueDequeueTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueFirstTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueRemoveTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueCountTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueCountTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueDequeueTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueDistinctTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueFilterTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueFindFirstTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueFirstTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueLimitTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueMapTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueMatchesTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueuePeekTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueForEachTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueReduceTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPEQueueSortedTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS;
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.SetTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.TestSetGenerator;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
import com.google.common.collect.testing.testers.CollectionSerializationEqualTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetAddAllTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetAddTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetCreationTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetEqualsTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetHashCodeTester;
|
||||||
|
import com.google.common.collect.testing.testers.SetRemoveTester;
|
||||||
|
import com.google.common.testing.SerializableTester;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetAddAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetAddTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetCreationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetEqualsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetRemoveTester;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SET_TEST_BUILDER KEY_GENERIC_TYPE extends COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||||
|
public static GENERIC_KEY_BRACES SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (SET_TEST_BUILDER KEY_GENERIC_TYPE) new SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
|
||||||
|
testers.add(CollectionSerializationEqualTester.class);
|
||||||
|
testers.add(SetAddAllTester.class);
|
||||||
|
testers.add(SetAddTester.class);
|
||||||
|
testers.add(SetCreationTester.class);
|
||||||
|
testers.add(SetHashCodeTester.class);
|
||||||
|
testers.add(SetEqualsTester.class);
|
||||||
|
testers.add(SetRemoveTester.class);
|
||||||
|
|
||||||
|
testers.add(FILE_KEY_TYPESetAddAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESetAddTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESetCreationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESetEqualsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESetRemoveTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(
|
||||||
|
FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder));
|
||||||
|
|
||||||
|
if (parentBuilder.getFeatures().contains(SERIALIZABLE)) {
|
||||||
|
derivedSuites.add(SetTestSuiteBuilder.using(new ReserializedSetGenerator<CLASS_TYPE>(parentBuilder.getSubjectGenerator()))
|
||||||
|
.named(getName() + " reserialized")
|
||||||
|
.withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
}
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ReserializedSetGenerator<E> implements TestSetGenerator<E> {
|
||||||
|
final OneSizeTestContainerGenerator<Collection<E>, E> gen;
|
||||||
|
|
||||||
|
private ReserializedSetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
|
||||||
|
this.gen = gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SampleElements<E> samples() {
|
||||||
|
return gen.samples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<E> create(Object... elements) {
|
||||||
|
return (Set<E>) SerializableTester.reserialize(gen.create(elements));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public E[] createArray(int length) {
|
||||||
|
return gen.createArray(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<E> order(List<E> insertionOrder) {
|
||||||
|
return gen.order(insertionOrder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<Feature<?>> computeReserializedCollectionFeatures(Set<Feature<?>> features) {
|
||||||
|
Set<Feature<?>> derivedFeatures = new HashSet<>(features);
|
||||||
|
#ignore
|
||||||
|
derivedFeatures.remove(SERIALIZABLE);
|
||||||
|
derivedFeatures.remove(SERIALIZABLE_INCLUDING_VIEWS);
|
||||||
|
#endignore
|
||||||
|
return derivedFeatures;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user