Compare commits
60
Commits
0.6.0
...
6722f399db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6722f399db | ||
|
|
8e39acef45 | ||
|
|
b065ebe9ba | ||
|
|
25a7cd060a | ||
|
|
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 |
@@ -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
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
# This workflow uses actions that are not certified by GitHub.
|
|
||||||
# They are provided by a third-party and are governed by
|
|
||||||
# separate terms of service, privacy policy, and support
|
|
||||||
# documentation.
|
|
||||||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
|
||||||
|
|
||||||
name: Latest Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
jdk: [8, 11, 14, 16, 17]
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up JDK ${{ matrix.jdk }}
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: ${{ matrix.jdk }}
|
|
||||||
- name: Validate Gradle wrapper
|
|
||||||
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
|
||||||
- name: Make gradlew executable
|
|
||||||
run: chmod +x ./gradlew
|
|
||||||
- name: Generate SourceCode with Gradle
|
|
||||||
run: ./gradlew generateGithubSource
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew build
|
|
||||||
@@ -0,0 +1,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
|
||||||
+14
@@ -30,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
|
||||||
|
|||||||
@@ -1,5 +1,76 @@
|
|||||||
# Changelog of versions
|
# Changelog of versions
|
||||||
|
|
||||||
|
### Version 0.7.1 (Unreleased)
|
||||||
|
- Added: ISizeProvider interface (Optimization Helper)
|
||||||
|
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
|
||||||
|
- Added: ToArray function into Iterable which uses ISizeProvider to reduce overhead of duplicating arrays.
|
||||||
|
- Fixed: putIfAbsent now replaces defaultValues
|
||||||
|
|
||||||
|
### Version 0.7.0
|
||||||
|
- Added: Over 11 Million Unit Tests to this library to ensure quality.
|
||||||
|
- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative
|
||||||
|
- Added: EnumMap specialized forEach implementation.
|
||||||
|
- Added: AbstractMap.remove now delegates to its primitive counterpart.
|
||||||
|
- Added: ConcurrentHashMap now implements ITrimmable
|
||||||
|
- Refactor: Removed a lot of disabled code from ArraySet.
|
||||||
|
- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required.
|
||||||
|
- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly
|
||||||
|
- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists.
|
||||||
|
- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists.
|
||||||
|
- 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.
|
||||||
|
- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely)
|
||||||
|
- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values.
|
||||||
|
- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should.
|
||||||
|
- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException.
|
||||||
|
- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed.
|
||||||
|
- Fixed: LinkedList.extractElement now returns the correct values.
|
||||||
|
- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed.
|
||||||
|
- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values.
|
||||||
|
- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
|
- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
|
- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
|
- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||||
|
- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found.
|
||||||
|
- Fixed: Linked/EnumMap array constructor was creating the wrong size values array.
|
||||||
|
- 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.
|
||||||
|
- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder.
|
||||||
|
- 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.
|
||||||
|
- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly.
|
||||||
|
- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty.
|
||||||
|
- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||||
|
- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||||
|
|
||||||
|
|
||||||
|
### Version 0.6.2
|
||||||
|
- 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.
|
||||||
|
- Added: AsyncBuilders now Support Array Inputs to create cleaner code.
|
||||||
|
- Changed: LinkedList.addBulk variable definition was triggering a false positive.
|
||||||
|
- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly.
|
||||||
|
- Fixed: SortedMap.sub/tail/headMap were looping into themselves.
|
||||||
|
- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer.
|
||||||
|
- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection.
|
||||||
|
- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes.
|
||||||
|
- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around.
|
||||||
|
- Fixed: LinkedList.addElements(EmptyInput) would crash.
|
||||||
|
- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one.
|
||||||
|
- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed.
|
||||||
|
- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place.
|
||||||
|
- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired.
|
||||||
|
- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value.
|
||||||
|
- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests.
|
||||||
|
- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive.
|
||||||
|
|
||||||
|
|
||||||
|
### Version 0.6.1
|
||||||
|
- Fixed: FIFO queue crashing when the last index is before the first index when peek is called.
|
||||||
|
- Fixed: FIFO queue only clears the array if it was in use.
|
||||||
|
- Added: Sorted Method for the stream replacing functions.
|
||||||
|
|
||||||
### Version 0.6.0
|
### Version 0.6.0
|
||||||
- Added: addOrGet for sets.
|
- Added: addOrGet for sets.
|
||||||
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
||||||
|
|||||||
+1082
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,21 @@
|
|||||||

|

|
||||||
|
[](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.
|
||||||
|
|
||||||
## Main Features:
|
## Main Features:
|
||||||
- ArrayLists / LinkedLists / CopyOnWriteLists
|
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||||
@@ -15,106 +26,34 @@ But its focus is a different one.
|
|||||||
- ConcurrentHashMaps
|
- ConcurrentHashMaps
|
||||||
- Priority Queues
|
- Priority Queues
|
||||||
- Streams & Functional Queries
|
- Streams & Functional Queries
|
||||||
- SplitIterators
|
- Split/Iterators
|
||||||
- Iterators
|
|
||||||
- Pairs
|
- Pairs
|
||||||
- Unary/Functions
|
- Unary/Functions
|
||||||
- Suppliers
|
- Suppliers
|
||||||
- Bi/Consumers
|
- Bi/Consumers
|
||||||
- AsyncBuilders
|
- AsyncBuilders
|
||||||
|
|
||||||
## Current Level of Stability
|
|
||||||
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
|
|
||||||
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 160k unit test covering Maps/Sets/Lists.
|
|
||||||
These tests cover Javas Collection API completely and ensuring a Stable implementation.
|
|
||||||
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
|
|
||||||
These will be expanded on as time goes on.
|
|
||||||
|
|
||||||
### Benchmarks
|
|
||||||
Benchmarks can be found here: [Click Me](https://github.com/Speiger/Primitive-Collections-Benchmarks/tree/master)
|
|
||||||
|
|
||||||
## Specialized Functions
|
|
||||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
|
||||||
To highlight things that may be wanted.
|
|
||||||
- Iterable:
|
|
||||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
|
||||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
|
||||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
|
||||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
|
||||||
- count: counts all valid elements in a collection.
|
|
||||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
|
||||||
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
|
|
||||||
- pour: a function that allows to collect all elements within the Collection
|
|
||||||
- Collection:
|
|
||||||
- addAll: addAll array version
|
|
||||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
|
||||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
|
||||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
|
||||||
(subCollections not supported for obvious reasons)
|
|
||||||
- toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference
|
|
||||||
- List:
|
|
||||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
|
||||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
|
||||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
|
||||||
- addIfAbsent/Present: adds a element only if absent/present in the list
|
|
||||||
- swapRemove: deletes a desired element and inserts the last element in its place instead of leftshifting elements.
|
|
||||||
- SortedSet:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
|
||||||
- pollFirst/Last: Allows to poll the first/last element of the set.
|
|
||||||
- Map:
|
|
||||||
- putAll: putAll but in Array form.
|
|
||||||
- putAllIfAbsent: Puts only the elements that are absent.
|
|
||||||
- addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
|
|
||||||
- subFrom (Only Primitive Values): allows to subtract from the value of a given key. If value reached getDefaultReturnValue() element will be removed.
|
|
||||||
- addToAll: Same as addTo but bulkVersion.
|
|
||||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
|
||||||
- mergeAll: BulkVersion of Merge function.
|
|
||||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
|
||||||
- Sorted Map:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
|
||||||
- getAndMoveToFirst/Last: gets the element and moves it to the first/last position. Replicating a Optional LinkedHashMap feature.
|
|
||||||
- pollFirst/LastKey: Allows to poll the first/last element.
|
|
||||||
- first/LastValue: Allows to get the first/last value from the Map.
|
|
||||||
|
|
||||||
|
|
||||||
# Notes about Versions
|
# Notes about Versions
|
||||||
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||||
Any breaking changes will be Documented (once 1.0 is released)
|
|
||||||
|
|
||||||
Also to save space every 0.0.x (Patch) that is 2 Minor Versions behind will be removed.
|
|
||||||
So if 0.5.0 is released every 0.3.x patch will be deleted, except for the last patch for that minor version.
|
|
||||||
|
|
||||||
# How to install
|
# How to install
|
||||||
Using Gradle:
|
Using Jitpack Gradle
|
||||||
```gradle
|
```gradle
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.speiger.com/repository/main"
|
url = "https://jitpack.io"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'de.speiger:Primitive-Collections:0.6.0'
|
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Direct:
|
|
||||||
|
|
||||||
| Version | Jar | Sources | Java Doc |
|
# SourceCode
|
||||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
The generated Sourcecode can be automatically build,
|
||||||
| 0.6.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.6.0/Primitive-Collections-0.6.0-javadoc.jar) |
|
but if you want to just browse around in it.
|
||||||
| 0.5.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-javadoc.jar) |
|
Check out the [Debug Branch](https://github.com/Speiger/Primitive-Collections/tree/debug/src/main/java/speiger/src/collections), which has the entire up to date code.
|
||||||
| 0.5.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-javadoc.jar) |
|
|
||||||
| 0.5.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-javadoc.jar) |
|
|
||||||
| 0.5.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-javadoc.jar) |
|
|
||||||
| 0.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) |
|
|
||||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
|
||||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
|
||||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
|
||||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
|
||||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
|
||||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
If you want to contribute.
|
If you want to contribute.
|
||||||
@@ -134,9 +73,5 @@ Please if you want to contribute follow the [Rule-Sheet](RuleSheet.md). It keeps
|
|||||||
The SourceCode can be generated via:
|
The SourceCode can be generated via:
|
||||||
/gradlew.bat generateSource
|
/gradlew.bat generateSource
|
||||||
|
|
||||||
to build the jar:
|
to generate SourceCode and build the jar:
|
||||||
/gradlew.bat build
|
/gradlew.bat build
|
||||||
do not combine the commands because they can not be executed at the same time.
|
|
||||||
|
|
||||||
## Current Down Sides (Random order)
|
|
||||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
|
||||||
+162
-5
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
id "jacoco"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
@@ -18,7 +19,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.6.0';
|
version = '0.7.0';
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||||
|
|
||||||
@@ -44,9 +45,11 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.0.7'
|
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||||
|
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateSource(type: JavaExec) {
|
task generateSource(type: JavaExec) {
|
||||||
@@ -61,7 +64,7 @@ task generateGithubSource(type: JavaExec) {
|
|||||||
description = 'Builds the sourcecode for Github Actions'
|
description = 'Builds the sourcecode for Github Actions'
|
||||||
classpath = sourceSets.builder.runtimeClasspath
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
args = ['false', 'true']
|
args = ['silent']
|
||||||
}
|
}
|
||||||
|
|
||||||
task forceGenerateSource(type: JavaExec) {
|
task forceGenerateSource(type: JavaExec) {
|
||||||
@@ -69,7 +72,15 @@ task forceGenerateSource(type: JavaExec) {
|
|||||||
description = 'Builds the sourcecode forceful'
|
description = 'Builds the sourcecode forceful'
|
||||||
classpath = sourceSets.builder.runtimeClasspath
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
args = ['true']
|
args = ['force']
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateTestSource(type: JavaExec) {
|
||||||
|
group = 'internal'
|
||||||
|
description = 'Builds the sourcecode for the Tests'
|
||||||
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
|
args = ['tests', 'silent']
|
||||||
}
|
}
|
||||||
|
|
||||||
task javadocJar(type: Jar) {
|
task javadocJar(type: Jar) {
|
||||||
@@ -82,6 +93,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()
|
||||||
@@ -91,8 +104,152 @@ artifacts {
|
|||||||
archives srcJar
|
archives srcJar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task testBooleans(type: Test) {
|
||||||
|
group 'tests'
|
||||||
|
description 'Tests all Boolean Collections'
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
includeTestsMatching "speiger.src.tests.booleans.**.*"
|
||||||
|
}
|
||||||
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
|
}
|
||||||
|
|
||||||
|
task testBytes(type: Test) {
|
||||||
|
group 'tests'
|
||||||
|
description 'Tests all Byte Collections'
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
includeTestsMatching "speiger.src.tests.bytes.**.*"
|
||||||
|
}
|
||||||
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
|
maxParallelForks = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
test {
|
||||||
useJUnit()
|
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 {
|
publishing {
|
||||||
|
|||||||
+402
@@ -0,0 +1,402 @@
|
|||||||
|
## Quality Of Life Features
|
||||||
|
New Specialized functions/classes that were added to increase performance and/or reduce allocations and/or for Quality of life.
|
||||||
|
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
Functions that increase performance or are quality of life in their nature.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Iterable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
## Functional Functions
|
||||||
|
|
||||||
|
Java adds themselves a lot of functional functions like,
|
||||||
|
- Stream:
|
||||||
|
- Map/FlatMap
|
||||||
|
- Filter/Distinct/Limit/Sorted
|
||||||
|
- Count/FindFirst/Collect
|
||||||
|
- Peek/ForEach/Reduce
|
||||||
|
- anyMatch/allMatch/NoneMatch
|
||||||
|
|
||||||
|
that allows to process a collection in a functional way.
|
||||||
|
But these require streams which have a lot of Overhead in their nature.
|
||||||
|
|
||||||
|
Luckly Primitive Collections adds replacement functions that provide the same functionality but with minimal overhead.
|
||||||
|
Here are some examples:
|
||||||
|
```java
|
||||||
|
public ObjectIterable<Path> toPath(ObjectIterable<String> iterable) {
|
||||||
|
return iterable.map(Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Path> toPath(Iterable<String> iterable) {
|
||||||
|
return ObjectIterables.map(iterable, Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(IntIterable iterable) {
|
||||||
|
return iterable.reduce(Integer::sum);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## AsyncAPI</summary>
|
||||||
|
|
||||||
|
The AsyncAPI is a Feature that simplifies the processing of Collections on a separate thread.
|
||||||
|
It uses the same concept as Javas Stream API but uses the light weight Functions from Primitive Collections to achieve the same thing.
|
||||||
|
Unlike Javas StreamAPI the AsyncAPI is always singleThreaded and more like Javas CompletableFuture, which you can await or let run Asynchronous.
|
||||||
|
|
||||||
|
The Goal is it to simplify the processing of Collections asynchronous.
|
||||||
|
Especially on tasks which don't have to be finished instantly but can be processed on the side.
|
||||||
|
|
||||||
|
Here is a example of how the API works.
|
||||||
|
```java
|
||||||
|
public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||||
|
potentialFiles.asAsync()
|
||||||
|
.map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
|
||||||
|
.forEach(Files::delete) //Creates the action (Required)
|
||||||
|
.callback(T -> {}} //Callback on completion, still offthread (Optional)
|
||||||
|
.execute() //Starts the task. (Required)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>Collection</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These are functions specific to the Collections interface, stuff that everyone wished it was present to be in the first place.
|
||||||
|
|
||||||
|
## AddAll (Array)
|
||||||
|
Adding Elements to a Collection usually requires either a for loop or a Arrays.wrap().
|
||||||
|
This isn't an issue with Primitive Collections.
|
||||||
|
```java
|
||||||
|
public void addMonths(ObjectCollection<String> months) {
|
||||||
|
months.addAll("January", "February", "March", "April", "May", "June", "July", "August", "September, "October", November", "December");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addElements(ObjectCollection<String> result, String[] elements) {
|
||||||
|
result.addAll(elements, 0, 5); //elements, offset, length
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## containsAny
|
||||||
|
Everyone hates comparing if 2 collections have part of each other included.
|
||||||
|
The solution usually requires for loops and keeping track if things were found or not.
|
||||||
|
And every Java Developer had this issue at least once and wished for a clean solution.
|
||||||
|
```java
|
||||||
|
public boolean hasMonths(ObjectCollection<Month> target, Collection<Month> toFind) {
|
||||||
|
return target.containsAny(toFind);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Copy
|
||||||
|
Collections get copied every now and then. There is only 2 ways that this happens.
|
||||||
|
Javas Clone API or using Constructor that supports collections.
|
||||||
|
Javas Clone API is kinda in a Zombie state, where it is supported or not. Its not really clear if you should use it or not.
|
||||||
|
The Clone CloneNotSupportedException isn't helping either, causing more janky code.
|
||||||
|
While a Constructor can only support so much and testing for every case isn't really viable.
|
||||||
|
|
||||||
|
So the decision was made to straight out not support clone and instead add a copy function which doesn't use a checked exception.
|
||||||
|
It works exactly like the clone function. In a sense where it creates a shallow copy. (SubCollections do not work for obvious reasons)
|
||||||
|
```java
|
||||||
|
public IntCollection copy(IntCollection original) {
|
||||||
|
return original.copy();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Primitive Streams
|
||||||
|
Since Javas Stream API is still really useful, even at its shortcomings, Primitive Collections provides easy access to it.
|
||||||
|
Generic Streams and the closest Primitive Stream will be provided. So a FloatCollection goes to a DoubleStream.
|
||||||
|
```java
|
||||||
|
public IntStream createStream(IntCollection source) {
|
||||||
|
return source.primitiveStream();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## RemoveAll/RetainAll with listener
|
||||||
|
Ever wanted use removeAll or retainAll and wanted to know what elements actually got deleted?
|
||||||
|
The usual solution is to create a copy and then apply it to the original and cross reference them.
|
||||||
|
Which leads to really messy code and just hasn't a clean solution.
|
||||||
|
Luckly Primitive Collections got you covered.
|
||||||
|
```java
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toRemove) {
|
||||||
|
files.removeAll(toRemove, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toKeep) {
|
||||||
|
files.retainFiles(toKeep, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## ToArray
|
||||||
|
Primitive Collections supports primitive/generic toArray functions for its Primitive Collections.
|
||||||
|
On top of that the Object side gets a Java9 function ported back to java8, which uses a functional Interface to create the backing array.
|
||||||
|
```java
|
||||||
|
public Integer[] toArray(IntCollection c) {
|
||||||
|
return c.toArray(new Integer[c.size]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] toArray(IntCollection c) {
|
||||||
|
return c.toIntArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] toArray(ObjectCollection<String> c) {
|
||||||
|
return c.toArray(String::new);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>List</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are List specific functions, a couple of these are from FastUtil.
|
||||||
|
|
||||||
|
## add/get/remove/extractElements
|
||||||
|
These functions really useful helper functions. 3 of which are copied from FastUtil. (extract is from Primitive Collections)
|
||||||
|
They are basically array forms of addAll, getAll, removeRange and removeAndGetRange. This is the simplest way to describe it.
|
||||||
|
|
||||||
|
Here some example:
|
||||||
|
```java
|
||||||
|
public void addAll(DoubleList list) {
|
||||||
|
list.addElements(0D, 12.2D, 3.5D, 4.2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getAll(DoubleList list, int amount) {
|
||||||
|
double[] result = new double[amount];
|
||||||
|
list.getElements(0, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRange(FloatList list) {
|
||||||
|
list.removeElements(5, 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] extractRange(FloatList list) {
|
||||||
|
return list.extractElements(5, 14); //Returns the removed elements
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addIfPresent/addIfAbsent
|
||||||
|
These two functions are simple helper functions that check internally if a element is present or absent before adding them to the List.
|
||||||
|
Removing the need for a contains or indexOf check every time you want to add a element.
|
||||||
|
While it is of course better to use a set, there is cases where this is still useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addElements(IntList list, int... numbersToAdd) {
|
||||||
|
for(int e : numbersToAdd) {
|
||||||
|
list.addIfAbsent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addExisting(ObjectList<String> list, String... textToAdd) {
|
||||||
|
for(String s : textToAdd) {
|
||||||
|
list.addIfPresent(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## SwapRemove
|
||||||
|
Lists when removing a Element shift usually the backing array to the left based to shrink the elements.
|
||||||
|
While that isn't computational expensive with LinkedLists, it is with ArrayLists.
|
||||||
|
Here comes swapRemove into play, which just removes the desired elements and instead of shifting left puts the last element in its place.
|
||||||
|
This reduces the data copying required down to 1 element instead of an array.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public int remove(IntList elements, int indexToRemove) {
|
||||||
|
return elements.swapRemove(indexToRemove);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unstable Sort (From FastUtil)
|
||||||
|
Unstable Sort uses a Faster but not as stable sorting algorithm to sort the Collection.
|
||||||
|
Stable doesn't mean crashing, but more like that the result isn't exactly perfectly sorted.
|
||||||
|
```java
|
||||||
|
public void sort(List<Month> list, Comparator<Month> sorter) {
|
||||||
|
list.unstableSort(sorter);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Map</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are based on the Map interface. Useful functions you really would want.
|
||||||
|
|
||||||
|
## addTo/subFrom
|
||||||
|
addTo (from FastUtil) and subFrom are mathematically functions that either add or subtract from the value of a given key.
|
||||||
|
And if the key isn't present or would result in the default value it will either add or remove the entry from the Map. Given the circumstance.
|
||||||
|
This is a really useful function and I wish FastUtil made it accessible by default but sadly it isn't.
|
||||||
|
To simplify the explanation:
|
||||||
|
- addTo if no element is present puts in the desired number, otherwise it sums up the two values.
|
||||||
|
- subFrom if a element is present subtracts from it, if the element reaches the default value it removes the element from the map. If not present it will be ignored.
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Month key, double averageTrainsRepaired) {
|
||||||
|
map.addTo(key, averageTrainsRepaired);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subFrom(Long2IntMap map, long key, double amount) {
|
||||||
|
map.subFrom(key, amount);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addToAll
|
||||||
|
Simple bulk version of the addTo function since sometimes you want to merge 2 maps for summing.
|
||||||
|
Especially if your work is multi-threaded this can become useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Object2DoubleMap<Month> trainsRepaired) {
|
||||||
|
map.addToAll(trainsRepaired);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## mergeAll
|
||||||
|
This is a simple bulk version of merge since merging 2 maps is more frequent then people might think and leads to cleaner code too.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ByteMap result, Long2ByteMap toMerge) {
|
||||||
|
result.mergeAll(toMerge);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAll (Array)
|
||||||
|
This allows to put keys and values as arrays instead of requiring a WrapperMap to insert the elements.
|
||||||
|
Not as useful as the Collections.addAll variant but still really useful.
|
||||||
|
```java
|
||||||
|
public void putAll(Int2DoubleMap map, int[] keys, double[] values) {
|
||||||
|
map.put(keys, values, 2, 15);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAllIfAbsent
|
||||||
|
putAll has this usual quirk where if a element is present it will replace the value, and sometimes this is not wanted.
|
||||||
|
While putIfAbsent exists it has no real mass form and makes iterative solutions really uneasy to use.
|
||||||
|
Here comes the helper function that gets rid of that problem.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ObjectMap<String> regionFiles, Long2ObjectMap<String> toAdd) {
|
||||||
|
regionFiles.putAllIfAbsent(toAdd);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## removeOrDefault
|
||||||
|
getOrDefault is a really useful function that find use cases all the time.
|
||||||
|
Sadly by default there is no variant of removeOrDefault, while it has less cases still could be used every now and then.
|
||||||
|
This function basically tries to remove a element, if it is not present it will just return your desired default.
|
||||||
|
```java
|
||||||
|
public Path removeCache(Long2ObjectMap<Path> caches, long key) {
|
||||||
|
return caches.removeOrDefault(key, Paths.get("nuclearFun"));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## supplyIfAbsent
|
||||||
|
This one is one of my favorites. computeIfAbsent is a really useful function.
|
||||||
|
But in 90% of the cases I use it the value is a collection.
|
||||||
|
This becomes really annoying since methodReferences are faster/cleaner then Lambdas in my opinion.
|
||||||
|
supplyIfAbsent is basically computeIfAbsent but without a key, perfect for the default constructor of a collection.
|
||||||
|
This is the whole reason it exists.
|
||||||
|
```java
|
||||||
|
public void example(Int2ObjectMap<List<String>> map, Int2ObjectMap<String> toAdd) {
|
||||||
|
for(Entry<String> entry : toAdd.entrySet()) {
|
||||||
|
map.supplyIfAbsent(entry.getKey(), ObjectArrayList::new).add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
# Interfaces
|
||||||
|
|
||||||
|
Interfaces that provide essential or quality of life features.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>ITrimmable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The ITrimmable is Accessor interface that allows you to access a couple helper functions to control the size of your collections.
|
||||||
|
This was created for the constant casting requirement to implementations just to shrink collections which get annoying over time.
|
||||||
|
|
||||||
|
## trim
|
||||||
|
This function basically trims down the backing implementation to use as little memory as required to store the elements in the collection.
|
||||||
|
Optionally a desired minimum size can be provided as of how low it should go at worst.
|
||||||
|
|
||||||
|
## clearAndTrim
|
||||||
|
when you want to reset a Collection completely you have 2 options. Clear it and then call trim, or recreate the collection.
|
||||||
|
clearAndTrim solves this problem by clearing the collection and trimming it in one go, reducing overhead to achieve such a thing.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>IArray</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
IArray is a Accessor interface that provides more access to collections by providing tools to grow your collection as needed.
|
||||||
|
While putAll/addAll try to ensure that you have enough room for your elements, this is not really a solution for all cases.
|
||||||
|
Sometimes you need to ensure the Collection is pre-initialized.
|
||||||
|
IArray grants you that control.
|
||||||
|
|
||||||
|
There is also a type specific that provides you access to the backing array implementation of Lists for faster Iteration but that is a really specific case.
|
||||||
|
|
||||||
|
## ensureCapacity
|
||||||
|
Ensures that your collection has enough storage for the elements you want to insert.
|
||||||
|
|
||||||
|
## elements (ITypeSpecificArray)
|
||||||
|
Allows you access to the backing array of a List which is for people who know what they are doing.
|
||||||
|
There is a lambda version of this function too which makes sure for synchronizedLists that you are the only one accessing the array.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedMap</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedMap is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedMap because the Set wasn't sorted.
|
||||||
|
So OrderedMap was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## getAndMoveToFirst/getAndMoveToLast
|
||||||
|
Returns a desired element and removing it to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## putAndMoveToFirst/putAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## firstKey/lastKey (Optional poll)
|
||||||
|
Provides access to the current first/last key of the Map.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
## firstValue/lastValue
|
||||||
|
Provides access to the current first/last value of the Map.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedSet</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedSet is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedSet because the Set wasn't sorted.
|
||||||
|
So OrderedSet was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## addAndMoveToFirst/addAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## first/last (Optional poll)
|
||||||
|
Provides access to the current first/last element of the set.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
@@ -2,6 +2,5 @@ jdk:
|
|||||||
- openjdk9
|
- openjdk9
|
||||||
install:
|
install:
|
||||||
- chmod +x ./gradlew
|
- chmod +x ./gradlew
|
||||||
- ./gradlew generateGithubSource
|
|
||||||
- ./gradlew build publishToMavenLocal
|
- ./gradlew build publishToMavenLocal
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package speiger.src.builder;
|
|||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public enum ClassType
|
public enum ClassType
|
||||||
{
|
{
|
||||||
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false"),
|
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false", "false"),
|
||||||
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0"),
|
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0", "(byte)-1"),
|
||||||
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0"),
|
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0", "(short)-1"),
|
||||||
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0"),
|
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0", "(char)-1"),
|
||||||
INT("int", "Integer", "Int", "ints", "INT", "0"),
|
INT("int", "Integer", "Int", "ints", "INT", "0", "-1"),
|
||||||
LONG("long", "Long", "Long", "longs", "LONG", "0L"),
|
LONG("long", "Long", "Long", "longs", "LONG", "0L", "-1L"),
|
||||||
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F"),
|
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F", "-1F"),
|
||||||
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D"),
|
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D", "-1D"),
|
||||||
OBJECT("T", "T", "Object", "objects", "OBJECT", "null");
|
OBJECT("T", "T", "Object", "objects", "OBJECT", "null", "null");
|
||||||
|
|
||||||
String keyType;
|
String keyType;
|
||||||
String classType;
|
String classType;
|
||||||
@@ -19,8 +19,9 @@ public enum ClassType
|
|||||||
String pathType;
|
String pathType;
|
||||||
String capType;
|
String capType;
|
||||||
String emptyValue;
|
String emptyValue;
|
||||||
|
String invalidValue;
|
||||||
|
|
||||||
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue)
|
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue, String invalidValue)
|
||||||
{
|
{
|
||||||
this.keyType = keyType;
|
this.keyType = keyType;
|
||||||
this.classType = classType;
|
this.classType = classType;
|
||||||
@@ -28,6 +29,7 @@ public enum ClassType
|
|||||||
this.pathType = pathType;
|
this.pathType = pathType;
|
||||||
this.capType = capType;
|
this.capType = capType;
|
||||||
this.emptyValue = emptyValue;
|
this.emptyValue = emptyValue;
|
||||||
|
this.invalidValue = invalidValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyType()
|
public String getKeyType()
|
||||||
@@ -50,6 +52,11 @@ public enum ClassType
|
|||||||
return classType;
|
return classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClassPath()
|
||||||
|
{
|
||||||
|
return this == OBJECT ? "Object" : classType;
|
||||||
|
}
|
||||||
|
|
||||||
public String getClassType(boolean value)
|
public String getClassType(boolean value)
|
||||||
{
|
{
|
||||||
return value && this == OBJECT ? "V" : classType;
|
return value && this == OBJECT ? "V" : classType;
|
||||||
@@ -90,6 +97,11 @@ public enum ClassType
|
|||||||
return emptyValue;
|
return emptyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInvalidValue()
|
||||||
|
{
|
||||||
|
return invalidValue;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isObject()
|
public boolean isObject()
|
||||||
{
|
{
|
||||||
return this == OBJECT;
|
return this == OBJECT;
|
||||||
|
|||||||
@@ -1,452 +0,0 @@
|
|||||||
package speiger.src.builder;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.UnaryOperator;
|
|
||||||
|
|
||||||
import speiger.src.builder.mappers.ArgumentMapper;
|
|
||||||
import speiger.src.builder.mappers.IMapper;
|
|
||||||
import speiger.src.builder.mappers.InjectMapper;
|
|
||||||
import speiger.src.builder.mappers.LineMapper;
|
|
||||||
import speiger.src.builder.mappers.SimpleMapper;
|
|
||||||
import speiger.src.builder.processor.TemplateProcess;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
|
||||||
public class GlobalVariables
|
|
||||||
{
|
|
||||||
List<IMapper> operators = new ArrayList<>();
|
|
||||||
Set<String> flags = new LinkedHashSet<>();
|
|
||||||
ClassType type;
|
|
||||||
ClassType valueType;
|
|
||||||
|
|
||||||
public GlobalVariables(ClassType type, ClassType subType)
|
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
valueType = subType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createVariables()
|
|
||||||
{
|
|
||||||
addSimpleMapper("VALUE_PACKAGE", valueType.getPathType());
|
|
||||||
addSimpleMapper("PACKAGE", type.getPathType());
|
|
||||||
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
|
||||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
|
||||||
addSimpleMapper("KEY_TYPE", type.getKeyType());
|
|
||||||
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
|
|
||||||
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
|
|
||||||
addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
|
|
||||||
|
|
||||||
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
|
|
||||||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
|
||||||
|
|
||||||
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
|
||||||
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
|
|
||||||
|
|
||||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
|
||||||
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "");
|
|
||||||
|
|
||||||
addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
|
||||||
addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
|
||||||
|
|
||||||
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
|
||||||
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
|
||||||
addSimpleMapper(" KEY_COMPAREABLE_TYPE", type.isObject() ? "<"+type.getKeyType()+" extends Comparable<T>>" : "");
|
|
||||||
|
|
||||||
addSimpleMapper(" KEY_SUPER_GENERIC_TYPE", type.isObject() ? "<? super "+type.getKeyType()+">" : "");
|
|
||||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
|
|
||||||
addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
|
||||||
|
|
||||||
addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : ""));
|
|
||||||
addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : ""));
|
|
||||||
|
|
||||||
addInjectMapper(" KEY_SPECIAL_GENERIC_TYPE", type.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" VALUE_SPECIAL_GENERIC_TYPE", valueType.isObject() ? "<%s>" : "").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" KSK_GENERIC_TYPE", type.isObject() ? "<%s, "+type.getKeyType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" KKS_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
|
||||||
addArgumentMapper(" KSS_GENERIC_TYPE", type.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" VSV_GENERIC_TYPE", valueType.isObject() ? "<%s, "+valueType.getValueType()+">" : "<%s>").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" VVS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>").removeBraces().setBraceType("<>");
|
|
||||||
addArgumentMapper(" VSS_GENERIC_TYPE", valueType.isObject() ? "<%1$s, %2$s>" : "<%2$s>").removeBraces().setBraceType("<>");
|
|
||||||
|
|
||||||
addSimpleMapper(" GENERIC_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+">" : "");
|
|
||||||
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
|
||||||
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
|
||||||
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
|
||||||
|
|
||||||
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
|
||||||
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
|
||||||
|
|
||||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
|
||||||
addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
|
|
||||||
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
|
|
||||||
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
|
|
||||||
if(type.needsCustomJDKType())
|
|
||||||
{
|
|
||||||
addSimpleMapper("JAVA_TYPE", type.getCustomJDKType().getKeyType());
|
|
||||||
addSimpleMapper("SANITY_CAST", "castTo"+type.getFileType());
|
|
||||||
}
|
|
||||||
addSimpleMapper("JAVA_CLASS", type.getCustomJDKType().getClassType());
|
|
||||||
if(valueType.needsCustomJDKType())
|
|
||||||
{
|
|
||||||
addSimpleMapper("SANITY_CAST_VALUE", "castTo"+valueType.getFileType());
|
|
||||||
}
|
|
||||||
addComment("@ArrayType", "@param <%s> the type of array that the operation should be applied");
|
|
||||||
addComment("@Type", "@param <%s> the type of elements maintained by this Collection");
|
|
||||||
addValueComment("@ValueArrayType", "@param <%s> the type of array that the operation should be applied");
|
|
||||||
addValueComment("@ValueType", "@param <%s> the type of elements maintained by this Collection");
|
|
||||||
addAnnontion("@PrimitiveOverride", "@Override");
|
|
||||||
addSimpleMapper("@PrimitiveDoc", "");
|
|
||||||
addAnnontion("@Primitive", "@Deprecated");
|
|
||||||
addValueAnnontion("@ValuePrimitiveOverride", "@Override");
|
|
||||||
addValueAnnontion("@ValuePrimitive", "@Deprecated");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createHelperVariables()
|
|
||||||
{
|
|
||||||
createHelperVars(type, false, "KEY");
|
|
||||||
createHelperVars(valueType, true, "VALUE");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createHelperVars(ClassType type, boolean value, String fix)
|
|
||||||
{
|
|
||||||
addArgumentMapper("EQUALS_"+fix+"_TYPE", "Objects.equals(%2$s, "+(type.isObject() ? "%1$s" : fix+"_TO_OBJ(%1$s)")+")").removeBraces();
|
|
||||||
addInjectMapper(fix+"_EQUALS_NOT_NULL", type.getComparableValue()+" != "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
|
||||||
addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces();
|
|
||||||
addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces();
|
|
||||||
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces();
|
|
||||||
|
|
||||||
addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
|
||||||
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
|
||||||
|
|
||||||
addInjectMapper(fix+"_TO_OBJ", type.isObject() ? "%s" : type.getClassType(value)+".valueOf(%s)").removeBraces();
|
|
||||||
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
|
|
||||||
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
|
|
||||||
|
|
||||||
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
|
||||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
|
|
||||||
|
|
||||||
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
|
||||||
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
|
||||||
addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
|
||||||
addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces();
|
|
||||||
addInjectMapper("NEW_CLASS"+(value ? "_VALUE" : "")+"_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createPreFunctions()
|
|
||||||
{
|
|
||||||
addSimpleMapper("ENTRY_SET", type.getFileType().toLowerCase()+"2"+valueType.getFileType()+"EntrySet");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createClassTypes()
|
|
||||||
{
|
|
||||||
addSimpleMapper("JAVA_PREDICATE", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Predicate");
|
|
||||||
addSimpleMapper("JAVA_CONSUMER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Consumer");
|
|
||||||
addSimpleMapper("JAVA_SUPPLIER", type.isPrimitiveBlocking() ? "" : "java.util.function."+type.getCustomJDKType().getFileType()+"Supplier");
|
|
||||||
addSimpleMapper("JAVA_FUNCTION", type.getFunctionClass(valueType));
|
|
||||||
addSimpleMapper("JAVA_BINARY_OPERATOR", type == ClassType.BOOLEAN ? "" : (type.isObject() ? "java.util.function.BinaryOperator" : "java.util.function."+type.getCustomJDKType().getFileType()+"BinaryOperator"));
|
|
||||||
addSimpleMapper("JAVA_UNARY_OPERATOR", type.isObject() ? "BinaryOperator" : type == ClassType.BOOLEAN ? "" : type.getCustomJDKType().getFileType()+"UnaryOperator");
|
|
||||||
addSimpleMapper("JAVA_SPLIT_ITERATOR", type.isPrimitiveBlocking() ? "Spliterator" : "Of"+type.getCustomJDKType().getFileType());
|
|
||||||
addSimpleMapper("JAVA_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getFileType()+"Stream");
|
|
||||||
addSimpleMapper("JAVA_BUFFER", type.getFileType()+"Buffer");
|
|
||||||
|
|
||||||
//Final Classes
|
|
||||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
|
||||||
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
|
|
||||||
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
|
|
||||||
addClassMapper("LINKED_LIST", "LinkedList");
|
|
||||||
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
|
||||||
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
|
||||||
addClassMapper("ARRAY_PRIORITY_QUEUE", "ArrayPriorityQueue");
|
|
||||||
addClassMapper("HEAP_PRIORITY_QUEUE", "HeapPriorityQueue");
|
|
||||||
addClassMapper("LINKED_CUSTOM_HASH_SET", "LinkedOpenCustomHashSet");
|
|
||||||
addClassMapper("LINKED_HASH_SET", "LinkedOpenHashSet");
|
|
||||||
addAbstractMapper("IMMUTABLE_HASH_SET", "Immutable%sOpenHashSet");
|
|
||||||
addClassMapper("CUSTOM_HASH_SET", "OpenCustomHashSet");
|
|
||||||
addClassMapper("HASH_SET", "OpenHashSet");
|
|
||||||
addAbstractBiMapper("IMMUTABLE_HASH_MAP", "Immutable%sOpenHashMap", "2");
|
|
||||||
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
|
||||||
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
|
||||||
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
|
||||||
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
|
|
||||||
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
|
||||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
|
||||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
|
||||||
addFunctionValueMappers("ENUM_MAP", valueType.isObject() ? "Enum2ObjectMap" : "Enum2%sMap");
|
|
||||||
addBiClassMapper("HASH_MAP", "OpenHashMap", "2");
|
|
||||||
addBiClassMapper("ARRAY_MAP", "ArrayMap", "2");
|
|
||||||
addBiClassMapper("IMMUTABLE_PAIR", "ImmutablePair", "");
|
|
||||||
addBiClassMapper("MUTABLE_PAIR", "MutablePair", "");
|
|
||||||
addClassMapper("RB_TREE_SET", "RBTreeSet");
|
|
||||||
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
|
|
||||||
addClassMapper("ARRAY_SET", "ArraySet");
|
|
||||||
|
|
||||||
//Abstract Classes
|
|
||||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
|
||||||
addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue");
|
|
||||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
|
||||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
|
||||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
|
||||||
addClassMapper("SUB_LIST", "SubList");
|
|
||||||
addAbstractMapper("BASE_TASK", "Base%sTask");
|
|
||||||
|
|
||||||
//Helper Classes
|
|
||||||
addClassMapper("LISTS", "Lists");
|
|
||||||
addClassMapper("SETS", "Sets");
|
|
||||||
addClassMapper("COLLECTIONS", "Collections");
|
|
||||||
addClassMapper("ARRAYS", "Arrays");
|
|
||||||
addClassMapper("PRIORITY_QUEUES", "PriorityQueues");
|
|
||||||
addClassMapper("SPLIT_ITERATORS", "Splititerators");
|
|
||||||
addClassMapper("ITERATORS", "Iterators");
|
|
||||||
addClassMapper("ITERABLES", "Iterables");
|
|
||||||
addBiClassMapper("MAPS", "Maps", "2");
|
|
||||||
|
|
||||||
//Interfaces
|
|
||||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
|
||||||
addClassMapper("BI_ITERATOR", "BidirectionalIterator");
|
|
||||||
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
|
||||||
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
|
|
||||||
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
|
|
||||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
|
||||||
addClassMapper("ITERATOR", "Iterator");
|
|
||||||
addClassMapper("ITERABLE", "Iterable");
|
|
||||||
addClassMapper("COLLECTION", "Collection");
|
|
||||||
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction");
|
|
||||||
addBiClassMapper("FUNCTION", "Function", "2");
|
|
||||||
addClassMapper("LIST_ITER", "ListIter");
|
|
||||||
addClassMapper("LIST", "List");
|
|
||||||
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
|
||||||
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
|
|
||||||
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
|
||||||
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
|
|
||||||
addBiClassMapper("MAP", "Map", "2");
|
|
||||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
|
||||||
addBiClassMapper("PAIR", "Pair", "");
|
|
||||||
addClassMapper("PRIORITY_QUEUE", "PriorityQueue");
|
|
||||||
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
|
||||||
addClassMapper("PREDICATE", "2BooleanFunction");
|
|
||||||
addClassMapper("SORTED_SET", "SortedSet");
|
|
||||||
addClassMapper("ORDERED_SET", "OrderedSet");
|
|
||||||
addClassMapper("SET", "Set");
|
|
||||||
addClassMapper("STRATEGY", "Strategy");
|
|
||||||
addClassMapper("STACK", "Stack");
|
|
||||||
addClassMapper("SUPPLIER", "Supplier");
|
|
||||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
|
||||||
addClassMapper("TASK", "Task");
|
|
||||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
|
||||||
if(type.isObject())
|
|
||||||
{
|
|
||||||
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
|
|
||||||
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
|
||||||
addSimpleMapper("CONSUMER", "Consumer");
|
|
||||||
addSimpleMapper("COMPARATOR", "Comparator");
|
|
||||||
addSimpleMapper("IARRAY", "IObjectArray");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(valueType.isObject())
|
|
||||||
{
|
|
||||||
addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
|
||||||
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
|
|
||||||
}
|
|
||||||
else addClassMapper("CONSUMER", "Consumer");
|
|
||||||
addClassMapper("COMPARATOR", "Comparator");
|
|
||||||
addFunctionMappers("IARRAY", "I%sArray");
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createFunctions()
|
|
||||||
{
|
|
||||||
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
|
||||||
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
|
||||||
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
|
|
||||||
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
|
||||||
addFunctionValueMapper("BULK_MERGE", "mergeAll");
|
|
||||||
addFunctionValueMappers("COMPUTE_IF_ABSENT", "compute%sIfAbsent");
|
|
||||||
addFunctionValueMappers("COMPUTE_IF_PRESENT", "compute%sIfPresent");
|
|
||||||
addFunctionValueMapper("COMPUTE", "compute");
|
|
||||||
addFunctionMapper("DEQUEUE_LAST", "dequeueLast");
|
|
||||||
addFunctionMapper("DEQUEUE", "dequeue");
|
|
||||||
addFunctionMappers("POLL_FIRST_ENTRY_KEY", "pollFirst%sKey");
|
|
||||||
addFunctionMappers("POLL_LAST_ENTRY_KEY", "pollLast%sKey");
|
|
||||||
addFunctionMapper("POLL_FIRST_KEY", "pollFirst");
|
|
||||||
addFunctionMapper("POLL_LAST_KEY", "pollLast");
|
|
||||||
addFunctionMappers("FIRST_ENTRY_KEY", "first%sKey");
|
|
||||||
addFunctionValueMappers("FIRST_ENTRY_VALUE", "first%sValue");
|
|
||||||
addFunctionMapper("FIRST_KEY", "first");
|
|
||||||
addFunctionMappers("LAST_ENTRY_KEY", "last%sKey");
|
|
||||||
addFunctionValueMappers("LAST_ENTRY_VALUE", "last%sValue");
|
|
||||||
addFunctionMappers("ENTRY_KEY", "get%sKey");
|
|
||||||
addFunctionValueMappers("ENTRY_VALUE", "get%sValue");
|
|
||||||
addFunctionMappers("KEY_ENTRY", "set%sKey");
|
|
||||||
addFunctionValueMappers("VALUE_ENTRY", "set%sValue");
|
|
||||||
addFunctionMapper("GET_KEY", "get");
|
|
||||||
if(type.isObject()) addFunctionValueMapper("GET_VALUE", valueType.isObject() ? "getObject" : "get");
|
|
||||||
else addSimpleMapper("GET_VALUE", "get");
|
|
||||||
addSimpleMapper("GET_JAVA", type.isObject() ? "get" : "getAs"+type.getCustomJDKType().getNonFileType());
|
|
||||||
addFunctionMapper("LAST_KEY", "last");
|
|
||||||
addFunctionValueMapper("MERGE", "merge");
|
|
||||||
addFunctionMapper("NEXT", "next");
|
|
||||||
addFunctionMapper("PREVIOUS", "previous");
|
|
||||||
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
|
||||||
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
|
|
||||||
else addSimpleMapper("REMOVE_VALUE", "remove");
|
|
||||||
addFunctionMapper("REMOVE_KEY", "rem");
|
|
||||||
addFunctionMapper("REMOVE_LAST", "removeLast");
|
|
||||||
addFunctionMapper("REMOVE", "remove");
|
|
||||||
addFunctionValueMappers("REPLACE_VALUES", valueType.isObject() ? "replaceObjects" : "replace%ss");
|
|
||||||
addFunctionMappers("REPLACE", type.isObject() ? "replaceObjects" : "replace%ss");
|
|
||||||
addFunctionMappers("SORT", "sort%ss");
|
|
||||||
addFunctionValueMappers("SUPPLY_IF_ABSENT", "supply%sIfAbsent");
|
|
||||||
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
|
|
||||||
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
|
|
||||||
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
|
|
||||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
|
||||||
addSimpleMapper("[SPACE]", " ");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalVariables createFlags()
|
|
||||||
{
|
|
||||||
flags.add("TYPE_"+type.getCapType());
|
|
||||||
flags.add("VALUE_"+valueType.getCapType());
|
|
||||||
if(type == valueType) flags.add("SAME_TYPE");
|
|
||||||
if(type.hasFunction(valueType)) flags.add("JDK_FUNCTION");
|
|
||||||
if(!type.needsCustomJDKType()) flags.add("JDK_TYPE");
|
|
||||||
if(!type.isPrimitiveBlocking()) flags.add("PRIMITIVES");
|
|
||||||
if(!valueType.isPrimitiveBlocking()) flags.add("VALUE_PRIMITIVES");
|
|
||||||
if(valueType.needsCustomJDKType()) flags.add("JDK_VALUE");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateProcess create(String fileName, String splitter, boolean valueOnly)
|
|
||||||
{
|
|
||||||
TemplateProcess process = new TemplateProcess(String.format(fileName+".java", (splitter != null ? type.getFileType()+splitter+valueType.getFileType() : (valueOnly ? valueType : type).getFileType())));
|
|
||||||
process.setPathBuilder(new PathBuilder(type.getPathType()));
|
|
||||||
process.addFlags(flags);
|
|
||||||
process.addMappers(operators);
|
|
||||||
return process;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassType getType()
|
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addClassMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+replacement));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+replacement));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addBiClassMapper(String pattern, String replacement, String splitter)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[KEY_"+pattern+"]", "KEY_"+pattern, type.getFileType()+splitter+type.getFileType()+replacement));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, valueType.getFileType()+splitter+valueType.getFileType()+replacement));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, type.getFileType()+splitter+valueType.getFileType()+replacement));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAbstractMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getFileType())));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAbstractBiMapper(String pattern, String replacement, String splitter)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getFileType()+splitter+valueType.getFileType())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFunctionMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, replacement+valueType.getNonFileType()));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+type.getNonFileType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFunctionValueMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement+valueType.getNonFileType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFunctionMappers(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"[VALUE_"+pattern+"]", "VALUE_"+pattern, String.format(replacement, valueType.getNonFileType())));
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, type.getNonFileType())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFunctionValueMappers(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, String.format(replacement, valueType.getNonFileType())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSimpleMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, replacement));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAnnontion(String pattern, String value)
|
|
||||||
{
|
|
||||||
if(type == ClassType.OBJECT) operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern));
|
|
||||||
else operators.add(new SimpleMapper(type.name()+"["+pattern+"]", pattern, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addValueAnnontion(String pattern, String value)
|
|
||||||
{
|
|
||||||
if(valueType == ClassType.OBJECT) operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern));
|
|
||||||
else operators.add(new SimpleMapper(valueType.name()+"["+pattern+"]", pattern, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addComment(String pattern, String value)
|
|
||||||
{
|
|
||||||
if(type == ClassType.OBJECT) operators.add(new InjectMapper(type.name()+"["+pattern+"]", pattern, value).removeBraces());
|
|
||||||
else operators.add(new LineMapper(type.name()+"["+pattern+"]", pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addValueComment(String pattern, String value)
|
|
||||||
{
|
|
||||||
if(valueType == ClassType.OBJECT) operators.add(new InjectMapper(valueType.name()+"["+pattern+"]", pattern, value).removeBraces());
|
|
||||||
else operators.add(new LineMapper(valueType.name()+"["+pattern+"]", pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
private InjectMapper addInjectMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
InjectMapper mapper = new InjectMapper(type.name()+"["+pattern+"]", pattern, replacement);
|
|
||||||
operators.add(mapper);
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArgumentMapper addArgumentMapper(String pattern, String replacement)
|
|
||||||
{
|
|
||||||
return addArgumentMapper(pattern, replacement, ", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArgumentMapper addArgumentMapper(String pattern, String replacement, String splitter)
|
|
||||||
{
|
|
||||||
ArgumentMapper mapper = new ArgumentMapper(type.name()+"["+pattern+"]", pattern, replacement, splitter);
|
|
||||||
operators.add(mapper);
|
|
||||||
return mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PathBuilder implements UnaryOperator<Path>
|
|
||||||
{
|
|
||||||
String before;
|
|
||||||
|
|
||||||
public PathBuilder(String before)
|
|
||||||
{
|
|
||||||
this.before = before;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Path apply(Path t)
|
|
||||||
{
|
|
||||||
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
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<>();
|
||||||
|
BiConsumer<String, RequiredType> requirements = VOID;
|
||||||
|
|
||||||
|
public ModulePackage(ClassType keyType, ClassType valueType) {
|
||||||
|
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 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.addMappers(mappers);
|
||||||
|
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() {
|
||||||
|
List<ModulePackage> list = new ArrayList<>();
|
||||||
|
for(ClassType key : TYPE) {
|
||||||
|
for(ClassType value : TYPE) {
|
||||||
|
list.add(new ModulePackage(key, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int sort(String key, String value) {
|
||||||
|
if(value.contains(key)) return 1;
|
||||||
|
else if(key.contains(value)) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
class PathBuilder implements UnaryOperator<Path> {
|
||||||
|
String before;
|
||||||
|
|
||||||
|
public PathBuilder(String before) {
|
||||||
|
this.before = before;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path apply(Path t) {
|
||||||
|
return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,20 +17,32 @@ import java.util.StringJoiner;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import speiger.src.builder.modules.AsyncModule;
|
||||||
|
import speiger.src.builder.modules.BaseModule;
|
||||||
|
import speiger.src.builder.modules.CollectionModule;
|
||||||
|
import speiger.src.builder.modules.FunctionModule;
|
||||||
|
import speiger.src.builder.modules.JavaModule;
|
||||||
|
import speiger.src.builder.modules.ListModule;
|
||||||
|
import speiger.src.builder.modules.MapModule;
|
||||||
|
import speiger.src.builder.modules.PairModule;
|
||||||
|
import speiger.src.builder.modules.PrioQueueModule;
|
||||||
|
import speiger.src.builder.modules.SetModule;
|
||||||
import speiger.src.builder.processor.TemplateProcess;
|
import speiger.src.builder.processor.TemplateProcess;
|
||||||
import speiger.src.builder.processor.TemplateProcessor;
|
import speiger.src.builder.processor.TemplateProcessor;
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||||
{
|
{
|
||||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
private static final int SPECIAL = 0x1; //Detects if the Builder is generating tests
|
||||||
Map<String, String> nameRemapper = new HashMap<>();
|
private static final int LOAD = 0x2; //If Configs should be loaded
|
||||||
Map<String, String> biRequired = new HashMap<>();
|
private static final int ANTI_SAVE = SPECIAL | LOAD; //If save should be disabled since load/save shouldn't happen at the same time.
|
||||||
Set<String> enumRequired = new HashSet<>();
|
private static final int SAVE = 0x4; //if the configuration should be created
|
||||||
public static final ClassType[] TYPE = ClassType.values();
|
List<ModulePackage> simplePackages = new ArrayList<>();
|
||||||
List<GlobalVariables> variables = new ArrayList<>();
|
List<ModulePackage> biPackages = new ArrayList<>();
|
||||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
List<ModulePackage> enumPackages = new ArrayList<>();
|
||||||
List<GlobalVariables> enumVariables = new ArrayList<>();
|
Map<String, RequiredType> requirements = new HashMap<>();
|
||||||
|
SettingsManager manager = new SettingsManager();
|
||||||
|
int flags;
|
||||||
|
|
||||||
public PrimitiveCollectionsBuilder()
|
public PrimitiveCollectionsBuilder()
|
||||||
{
|
{
|
||||||
@@ -51,6 +64,28 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PrimitiveCollectionsBuilder setFlags(int flags) {
|
||||||
|
this.flags = flags;
|
||||||
|
if((flags & ANTI_SAVE) != 0) {
|
||||||
|
this.flags &= ~SAVE;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrimitiveCollectionsBuilder createTests(boolean silent, int flags) {
|
||||||
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
|
Paths.get("src/builder/resources/speiger/assets/tests/templates/"),
|
||||||
|
Paths.get("src/test/java/speiger/src/tests/"),
|
||||||
|
Paths.get("src/builder/resources/speiger/assets/tests/")).setFlags(flags | SPECIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrimitiveCollectionsBuilder createTesters(boolean silent, int flags) {
|
||||||
|
return new PrimitiveCollectionsBuilder(silent,
|
||||||
|
Paths.get("src/builder/resources/speiger/assets/testers/templates/"),
|
||||||
|
Paths.get("src/test/java/speiger/src/testers/"),
|
||||||
|
Paths.get("src/builder/resources/speiger/assets/testers/")).setFlags(flags | SPECIAL);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isFileValid(Path fileName)
|
protected boolean isFileValid(Path fileName)
|
||||||
{
|
{
|
||||||
@@ -72,7 +107,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
@Override
|
@Override
|
||||||
protected void afterFinish()
|
protected void afterFinish()
|
||||||
{
|
{
|
||||||
if(getVersion() > 8)
|
if((flags & SPECIAL) == 0 && getVersion() > 8)
|
||||||
{
|
{
|
||||||
Path basePath = Paths.get("src/main/java");
|
Path basePath = Paths.get("src/main/java");
|
||||||
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
||||||
@@ -87,100 +122,62 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init()
|
protected void init()
|
||||||
{
|
{
|
||||||
variables.clear();
|
prepPackages();
|
||||||
for(ClassType clzType : TYPE)
|
//Init Modules here
|
||||||
{
|
addModule(new JavaModule());
|
||||||
for(ClassType subType : TYPE)
|
addModule(new FunctionModule());
|
||||||
{
|
addModule(new CollectionModule());
|
||||||
create(clzType, subType);
|
addModule(new PrioQueueModule());
|
||||||
}
|
addModule(new ListModule());
|
||||||
}
|
addModule(new SetModule());
|
||||||
enumRequired.add("EnumMap");
|
addModule(new MapModule());
|
||||||
enumRequired.add("LinkedEnumMap");
|
addModule(new PairModule());
|
||||||
biRequired.put("BiConsumer", "");
|
addModule(new AsyncModule());
|
||||||
biRequired.put("UnaryOperator", "");
|
finishPackages();
|
||||||
biRequired.put("Pair", "");
|
|
||||||
biRequired.put("MutablePair", "");
|
|
||||||
biRequired.put("ImmutablePair", "");
|
|
||||||
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
|
||||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
|
||||||
nameRemapper.put("IArray", "I%sArray");
|
|
||||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
|
||||||
nameRemapper.put("AbstractCollection", "Abstract%sCollection");
|
|
||||||
nameRemapper.put("AbstractPriorityQueue", "Abstract%sPriorityQueue");
|
|
||||||
nameRemapper.put("AbstractSet", "Abstract%sSet");
|
|
||||||
nameRemapper.put("AbstractList", "Abstract%sList");
|
|
||||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
|
||||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
|
||||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
|
||||||
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
|
||||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
|
||||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
|
||||||
|
|
||||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
|
||||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
|
||||||
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void create(ClassType mainType, ClassType subType)
|
public void addModule(BaseModule module)
|
||||||
{
|
{
|
||||||
GlobalVariables type = new GlobalVariables(mainType, subType);
|
module.setManager(manager);
|
||||||
type.createFlags();
|
biPackages.forEach(module::init);
|
||||||
type.createHelperVariables();
|
module.cleanup();
|
||||||
type.createVariables();
|
|
||||||
type.createPreFunctions();
|
|
||||||
type.createClassTypes();
|
|
||||||
type.createFunctions();
|
|
||||||
if(mainType == subType) variables.add(type);
|
|
||||||
biVariables.add(type);
|
|
||||||
if(mainType.isObject()) enumVariables.add(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addBiClass(String...classNames)
|
private void finishPackages()
|
||||||
{
|
{
|
||||||
for(String s : classNames)
|
biPackages.forEach(ModulePackage::finish);
|
||||||
{
|
if((flags & SAVE) != 0) manager.save();
|
||||||
biRequired.put(s, "2");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addBlockage(ClassType type, String...args)
|
private void prepPackages()
|
||||||
{
|
{
|
||||||
for(String s : args)
|
if((flags & LOAD) != 0) manager.load();
|
||||||
|
for(ModulePackage entry : ModulePackage.createPackages())
|
||||||
{
|
{
|
||||||
EnumSet<ClassType> set = blocked.get(s);
|
entry.setRequirements(requirements::put);
|
||||||
if(set == null)
|
biPackages.add(entry);
|
||||||
{
|
if(entry.isSame()) simplePackages.add(entry);
|
||||||
set = EnumSet.noneOf(ClassType.class);
|
if(entry.isEnumValid()) enumPackages.add(entry);
|
||||||
blocked.put(s, set);
|
}
|
||||||
}
|
|
||||||
set.add(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createProcesses(String name, Consumer<TemplateProcess> acceptor)
|
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
|
||||||
{
|
{
|
||||||
String splitter = biRequired.get(name);
|
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
|
||||||
boolean valueRequired = enumRequired.contains(name);
|
for(int i = 0,m=packages.size();i<m;i++)
|
||||||
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
|
||||||
EnumSet<ClassType> types = blocked.get(name);
|
|
||||||
for(int i = 0,m=vars.size();i<m;i++)
|
|
||||||
{
|
{
|
||||||
GlobalVariables type = vars.get(i);
|
packages.get(i).process(fileName, process);
|
||||||
if(types == null || !types.contains(type.getType()))
|
|
||||||
{
|
|
||||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {
|
||||||
if(enumRequired.contains(name)) return enumVariables;
|
if(type == null) return simplePackages;
|
||||||
if(bi) return biVariables;
|
if(type == RequiredType.BI_CLASS) return biPackages;
|
||||||
return variables;
|
if(type == RequiredType.ENUM) return enumPackages;
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getModuleInfo(Path basePath) {
|
private String getModuleInfo(Path basePath) {
|
||||||
@@ -236,28 +233,22 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(args.length == 0) {
|
Set<String> flags = new HashSet<>(Arrays.asList(args));
|
||||||
new PrimitiveCollectionsBuilder().process(false);
|
boolean silent = flags.contains("silent");
|
||||||
} else if(args.length == 1) {
|
boolean force = flags.contains("force");
|
||||||
new PrimitiveCollectionsBuilder().process(Boolean.parseBoolean(args[0]));
|
boolean tests = flags.contains("tests");
|
||||||
} else if(args.length == 2) {
|
boolean forceTests = flags.contains("force-tests");
|
||||||
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[1])).process(Boolean.parseBoolean(args[0]));
|
boolean load = flags.contains("load");
|
||||||
} else if(args.length == 3) {
|
boolean save = !flags.contains("save");
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
int flag = (load ? LOAD : 0) | (save ? SAVE : 0);
|
||||||
} else if(args.length == 4) {
|
// new PrimitiveCollectionsBuilder(silent).test();
|
||||||
new PrimitiveCollectionsBuilder(false, Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
new PrimitiveCollectionsBuilder(silent).setFlags(flag).process(force);
|
||||||
} else if(args.length == 4) {
|
if(tests) {
|
||||||
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[4]), Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
createTests(silent, flag).process(force || forceTests);
|
||||||
} else {
|
createTesters(silent, flag).process(force || forceTests);
|
||||||
System.out.println("Invalid argument count passed in");
|
}
|
||||||
System.exit(1);
|
}
|
||||||
}
|
catch(InterruptedException | IOException e)
|
||||||
}
|
|
||||||
catch(InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package speiger.src.builder;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public enum RequiredType
|
||||||
|
{
|
||||||
|
BI_CLASS,
|
||||||
|
ENUM
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
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, String entry)
|
||||||
|
{
|
||||||
|
if(!loaded) return true;
|
||||||
|
if(!isEnabled(data, base.getModuleName())) return false;
|
||||||
|
JsonObject result = getObject(data, keyType.getClassPath());
|
||||||
|
if(base.isBiModule()) result = getObject(result, valueType.getClassPath());
|
||||||
|
result = getObject(result, base.getModuleName());
|
||||||
|
return result.size() <= 0 || (isEnabled(result, "enabled") && isEnabled(result, entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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) {
|
||||||
|
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());
|
||||||
|
if(bi) {
|
||||||
|
result = getObject(result, valueType.getClassPath());
|
||||||
|
}
|
||||||
|
result.add(moduleName, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject getObject(JsonObject data, String name) {
|
||||||
|
JsonObject obj = data.getAsJsonObject(name);
|
||||||
|
if(obj == null) {
|
||||||
|
obj = new JsonObject();
|
||||||
|
data.add(name, obj);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEnabled(JsonObject obj, String key) {
|
||||||
|
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class AsyncModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Async"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers() {}
|
||||||
|
@Override
|
||||||
|
protected void loadTestClasses() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadClasses()
|
||||||
|
{
|
||||||
|
//Abstract Classes
|
||||||
|
addAbstractMapper("BASE_TASK", "Base%sTask");
|
||||||
|
|
||||||
|
//Interfaces
|
||||||
|
addClassMapper("TASK", "Task");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,178 @@
|
|||||||
|
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();
|
||||||
|
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 loadFlags();
|
||||||
|
|
||||||
|
public abstract String getModuleName();
|
||||||
|
public boolean isBiModule() { return false; }
|
||||||
|
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
|
||||||
|
|
||||||
|
protected boolean isModuleEnabled(String name) {
|
||||||
|
if(manager == null) return true;
|
||||||
|
return manager.isModuleEnabled(this, keyType, valueType, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addFlag(String name) {
|
||||||
|
entry.addFlag(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,99 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class CollectionModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Collection"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockades(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
|
||||||
|
private void loadBlockades()
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
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,71 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class FunctionModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Function"; }
|
||||||
|
@Override
|
||||||
|
public boolean isBiModule() { return true; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockades(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
@Override
|
||||||
|
protected void loadTestClasses() {}
|
||||||
|
|
||||||
|
private void loadBlockades()
|
||||||
|
{
|
||||||
|
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers()
|
||||||
|
{
|
||||||
|
addBiRequirement("BiConsumer", "");
|
||||||
|
addBiRequirement("UnaryOperator", "");
|
||||||
|
addBiRequirement("Function");
|
||||||
|
addRemapper("BiConsumer", "%sConsumer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions()
|
||||||
|
{
|
||||||
|
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
|
||||||
|
addSimpleMapper("TEST_VALUE", keyType.isObject() ? "getBoolean" : "get");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadClasses()
|
||||||
|
{
|
||||||
|
//Interfaces
|
||||||
|
addBiClassMapper("BI_CONSUMER", "Consumer", "");
|
||||||
|
addClassMapper("BI_TO_OBJECT_CONSUMER", "ObjectConsumer");
|
||||||
|
addAbstractMapper("BI_FROM_OBJECT_CONSUMER", "Object%sConsumer");
|
||||||
|
addClassMapper("TO_OBJECT_FUNCTION", "2ObjectFunction");
|
||||||
|
addBiClassMapper("FUNCTION", "Function", "2");
|
||||||
|
addClassMapper("PREDICATE", "2BooleanFunction");
|
||||||
|
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,201 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class JavaModule extends BaseModule
|
||||||
|
{
|
||||||
|
@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());
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions()
|
||||||
|
{
|
||||||
|
addSimpleMapper("APPLY_KEY_VALUE", keyType.isObject() ? "apply" : "applyAs"+keyType.getNonFileType());
|
||||||
|
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
||||||
|
addSimpleMapper("APPLY_CAST", "applyAs"+keyType.getCustomJDKType().getNonFileType());
|
||||||
|
addSimpleMapper("APPLY", keyType.isObject() ? "apply" : "applyAs"+keyType.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()
|
||||||
|
{
|
||||||
|
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_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(" 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", 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,87 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ListModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "List"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockedFiles(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
|
||||||
|
private void loadBlockedFiles()
|
||||||
|
{
|
||||||
|
if(keyType.isObject()) {
|
||||||
|
addBlockedFiles("ListFillBufferTester");
|
||||||
|
}
|
||||||
|
if(keyType == ClassType.BOOLEAN) {
|
||||||
|
addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadRemappers()
|
||||||
|
{
|
||||||
|
//Main Classes
|
||||||
|
addRemapper("AbstractList", "Abstract%sList");
|
||||||
|
addRemapper("ImmutableList", "Immutable%sList");
|
||||||
|
addRemapper("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
||||||
|
|
||||||
|
//Test Classes
|
||||||
|
addRemapper("AbstractListTester", "Abstract%sListTester");
|
||||||
|
addRemapper("AbstractListIndexOfTester", "Abstract%sListIndexOfTester");
|
||||||
|
addRemapper("TestListGenerator", "Test%sListGenerator");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions()
|
||||||
|
{
|
||||||
|
addFunctionMapper("GET_KEY", "get");
|
||||||
|
addFunctionMapper("REMOVE_LAST", "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("ASYNC_BUILDER", "AsyncBuilder");
|
||||||
|
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,204 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class MapModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Map"; }
|
||||||
|
@Override
|
||||||
|
public boolean isBiModule() { return true; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockades(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
|
||||||
|
private void loadBlockades()
|
||||||
|
{
|
||||||
|
if(keyType == ClassType.BOOLEAN)
|
||||||
|
{
|
||||||
|
//Main Classes
|
||||||
|
addBlockedFiles("SortedMap", "NavigableMap", "RBTreeMap", "AVLTreeMap");
|
||||||
|
addBlockedFiles("OrderedMap", "ArrayMap", "LinkedOpenHashMap", "LinkedOpenCustomHashMap");
|
||||||
|
addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||||
|
addBlockedFiles("ImmutableOpenHashMap", "OpenHashMap", "OpenCustomHashMap");
|
||||||
|
|
||||||
|
//Test Classes
|
||||||
|
addBlockedFiles("TestMap", "MapTests", "MapTestSuiteBuilder", "MapConstructorTests", "TestMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester");
|
||||||
|
addBlockedFiles("TestSortedMapGenerator", "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");
|
||||||
|
addSimpleMapper("GET_JAVA", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
|
||||||
|
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,41 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class PairModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Pair"; }
|
||||||
|
@Override
|
||||||
|
public boolean isBiModule() { return true; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions() {}
|
||||||
|
@Override
|
||||||
|
protected void loadTestClasses() {}
|
||||||
|
|
||||||
|
@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,70 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class PrioQueueModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "PriorityQueue"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockades(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
@Override
|
||||||
|
protected void loadFunctions() {}
|
||||||
|
|
||||||
|
private void loadBlockades()
|
||||||
|
{
|
||||||
|
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,105 @@
|
|||||||
|
package speiger.src.builder.modules;
|
||||||
|
|
||||||
|
import speiger.src.builder.ClassType;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SetModule extends BaseModule
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getModuleName() { return "Set"; }
|
||||||
|
@Override
|
||||||
|
protected void loadVariables() { loadBlockades(); }
|
||||||
|
@Override
|
||||||
|
protected void loadFlags() {}
|
||||||
|
|
||||||
|
private void loadBlockades()
|
||||||
|
{
|
||||||
|
if(keyType == ClassType.BOOLEAN)
|
||||||
|
{
|
||||||
|
//Main Classes
|
||||||
|
addBlockedFiles("SortedSet", "NavigableSet", "AVLTreeSet", "RBTreeSet");
|
||||||
|
addBlockedFiles("OrderedSet", "ArraySet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||||
|
addBlockedFiles("OpenHashSet", "OpenCustomHashSet", "ImmutableOpenHashSet");
|
||||||
|
|
||||||
|
//Test Classes
|
||||||
|
addBlockedFiles("SetTests", "SetTestSuiteBuilder");
|
||||||
|
addBlockedFiles("OrderedSetTestSuiteBuilder", "TestOrderedSetGenerator", "OrderedSetMoveTester", "OrderedSetNavigationTester", "OrderedMapNavigationTester", "OrderedMapTestSuiteBuilder", "OrderedSetIterationTester");
|
||||||
|
addBlockedFiles("SortedSetTestSuiteBuilder", "TestSortedSetGenerator", "SortedSetNaviationTester", "SortedSetSubsetTestSetGenerator", "SortedSetIterationTester", "SortedSetNaviationTester");
|
||||||
|
addBlockedFiles("NavigableSetTestSuiteBuilder", "TestNavigableSetGenerator", "NavigableSetNavigationTester");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -230,6 +230,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
KEY_TYPE e = iter.NEXT();
|
KEY_TYPE e = iter.NEXT();
|
||||||
if(!c.contains(e)) {
|
if(!c.contains(e)) {
|
||||||
|
r.accept(e);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
@@ -256,6 +257,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||||
ITERATORS.unwrap(a, iterator());
|
ITERATORS.unwrap(a, iterator());
|
||||||
|
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -16,13 +16,14 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||||
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific {@link Collection} that reduces (un)boxing
|
* A Type-Specific {@link Collection} that reduces (un)boxing
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
|
public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
{
|
{
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
|
|||||||
+64
@@ -5,9 +5,12 @@ import java.util.function.Consumer;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
#else
|
#else
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
@@ -24,6 +27,7 @@ import speiger.src.collections.PACKAGE.utils.ASYNC_BUILDER;
|
|||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
import speiger.src.collections.PACKAGE.utils.ITERABLES;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||||
@@ -115,6 +119,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
* @param <V> The return type supplier.
|
* @param <V> The return type supplier.
|
||||||
* @param <E> The return type.
|
* @param <E> The return type.
|
||||||
* @return a new Iterable that returns the desired result
|
* @return a new Iterable that returns the desired result
|
||||||
|
* @note does not support TO_ARRAY optimizations.
|
||||||
*/
|
*/
|
||||||
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
default <E, V extends Iterable<E>> ObjectIterable<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
return ITERABLES.flatMap(this, mapper);
|
return ITERABLES.flatMap(this, mapper);
|
||||||
@@ -125,6 +130,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
* @param mapper the flatMapping function
|
* @param mapper the flatMapping function
|
||||||
* @param <E> The return type.
|
* @param <E> The return type.
|
||||||
* @return a new Iterable that returns the desired result
|
* @return a new Iterable that returns the desired result
|
||||||
|
* @note does not support TO_ARRAY optimizations.
|
||||||
*/
|
*/
|
||||||
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
default <E> ObjectIterable<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
return ITERABLES.arrayFlatMap(this, mapper);
|
return ITERABLES.arrayFlatMap(this, mapper);
|
||||||
@@ -134,6 +140,7 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
* A Helper function to reduce the usage of Streams and allows to filter out unwanted elements
|
||||||
* @param filter the elements that should be kept.
|
* @param filter the elements that should be kept.
|
||||||
* @return a Iterable that filtered out all unwanted elements
|
* @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) {
|
default ITERABLE KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
return ITERABLES.filter(this, filter);
|
return ITERABLES.filter(this, filter);
|
||||||
@@ -142,11 +149,21 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
/**
|
/**
|
||||||
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
* 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
|
* @return a Iterable that filtered out all duplicated elements
|
||||||
|
* @note does not support TO_ARRAY optimizations.
|
||||||
*/
|
*/
|
||||||
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||||
return ITERABLES.distinct(this);
|
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
|
* 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
|
* @param limit the amount of elements it should be limited to
|
||||||
@@ -156,6 +173,15 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
return ITERABLES.limit(this, 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
|
* 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
|
* @param action the action that should be applied
|
||||||
@@ -193,6 +219,44 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
return pour(new LINKED_HASH_SETBRACES());
|
return pour(new LINKED_HASH_SETBRACES());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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.
|
||||||
|
* @return a new Array of all elements
|
||||||
|
*/
|
||||||
|
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(this);
|
||||||
|
if(prov != null) {
|
||||||
|
int size = prov.size();
|
||||||
|
if(size >= 0) {
|
||||||
|
KEY_TYPE[] array = action.get(size);
|
||||||
|
ITERATORS.unwrap(array, iterator());
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ITERATORS.pour(iterator()).TO_ARRAY(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 ITERATORS.pour(iterator()).TO_ARRAY();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* Helper function to reduce stream usage that allows to filter for any matches.
|
* Helper function to reduce stream usage that allows to filter for any matches.
|
||||||
|
|||||||
+26
-14
@@ -308,14 +308,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
SanityChecks.checkArrayCapacity(size, from, length);
|
SanityChecks.checkArrayCapacity(size, from, length);
|
||||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
return list.getElements(from+this.offset, a, offset, length);
|
return list.getElements(from+parentOffset, a, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeElements(int from, int to) {
|
public void removeElements(int from, int to) {
|
||||||
if(to-from <= 0) return;
|
if(to-from <= 0) return;
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
list.removeElements(from+parentOffset, to+parentOffset);
|
list.removeElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= to - from;
|
||||||
}
|
}
|
||||||
@@ -324,9 +324,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,9 +334,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,19 +344,25 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.GET_KEY(offset+index);
|
return list.GET_KEY(parentOffset+index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE element) {
|
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.set(offset+index, element);
|
return list.set(parentOffset+index, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE swapRemove(int index) {
|
public KEY_TYPE swapRemove(int index) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
KEY_TYPE result = list.swapRemove(index+parentOffset);
|
if(index == size-1) {
|
||||||
|
KEY_TYPE result = list.REMOVE(parentOffset+size-1);
|
||||||
|
size--;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
KEY_TYPE result = list.set(index+parentOffset, list.GET_KEY(parentOffset+size-1));
|
||||||
|
list.REMOVE(parentOffset+size-1);
|
||||||
size--;
|
size--;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -386,7 +392,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||||
return new SubList(list, offset, fromIndex, toIndex);
|
return new SubList(this, offset, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkSubRange(int index) {
|
protected void checkSubRange(int index) {
|
||||||
@@ -460,15 +466,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
list.add(index++, e);
|
list.add(index, e);
|
||||||
|
index++;
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (list.size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,6 +485,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -540,15 +549,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
ABSTRACT_LIST.this.add(index++, e);
|
ABSTRACT_LIST.this.add(index, e);
|
||||||
|
index++;
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,6 +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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
* @param size the minimum initial size of the Backing array
|
* @param size the minimum initial size of the Backing array
|
||||||
*/
|
*/
|
||||||
public ARRAY_LIST(int size) {
|
public ARRAY_LIST(int size) {
|
||||||
|
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||||
data = NEW_KEY_ARRAY(size);
|
data = NEW_KEY_ARRAY(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,8 +325,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
if(length <= 0) return;
|
if(length <= 0) return;
|
||||||
checkAddRange(from);
|
checkAddRange(from);
|
||||||
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
grow(size + length);
|
grow(size + length);
|
||||||
if(from != size) System.arraycopy(data, from, data, from+length, size - length);
|
if(from != size) System.arraycopy(data, from, data, from+length, size - from);
|
||||||
size+=length;
|
size+=length;
|
||||||
System.arraycopy(a, offset, data, from, length);
|
System.arraycopy(a, offset, data, from, length);
|
||||||
}
|
}
|
||||||
@@ -361,11 +363,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
int length = to - from;
|
int length = to - from;
|
||||||
if(length <= 0) return;
|
if(length <= 0) return;
|
||||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||||
|
size -= length;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
for(int i = 0;i<length;i++)
|
for(int i = 0;i<length;i++)
|
||||||
data[i+to] = null;
|
data[i+size] = null;
|
||||||
#endif
|
#endif
|
||||||
size -= length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@@ -381,13 +383,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
checkRange(from);
|
checkRange(from);
|
||||||
checkAddRange(to);
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
|
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||||
K[] a = ARRAYS.newArray(type, length);
|
K[] a = ARRAYS.newArray(type, length);
|
||||||
if(length <= 0) return a;
|
|
||||||
System.arraycopy(data, from, a, 0, length);
|
System.arraycopy(data, from, a, 0, length);
|
||||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||||
|
size -= length;
|
||||||
for(int i = 0;i<length;i++)
|
for(int i = 0;i<length;i++)
|
||||||
data[i+to] = null;
|
data[i+size] = null;
|
||||||
size -= length;
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+427
-39
@@ -9,8 +9,9 @@ import java.util.Iterator;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
#if TYPE_OBJECT
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
#if TYPE_OBJECT
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -155,6 +156,14 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private void setArray(KEY_TYPE[] data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private KEY_TYPE[] getArray() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends the specified element to the end of this list.
|
* Appends the specified element to the end of this list.
|
||||||
*
|
*
|
||||||
@@ -365,6 +374,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
KEY_TYPE[] data = this.data;
|
KEY_TYPE[] data = this.data;
|
||||||
int size = data.length;
|
int size = data.length;
|
||||||
if(from < 0 || from > size) throw new IndexOutOfBoundsException("Index: " + from + ", Size: " + size);
|
if(from < 0 || from > size) throw new IndexOutOfBoundsException("Index: " + from + ", Size: " + size);
|
||||||
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
KEY_TYPE[] newElements;
|
KEY_TYPE[] newElements;
|
||||||
if(from == size) {
|
if(from == size) {
|
||||||
newElements = Arrays.copyOf(data, size+length);
|
newElements = Arrays.copyOf(data, size+length);
|
||||||
@@ -409,6 +419,8 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void removeElements(int from, int to) {
|
public void removeElements(int from, int to) {
|
||||||
|
checkRange(from);
|
||||||
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
if(length <= 0) return;
|
if(length <= 0) return;
|
||||||
ReentrantLock lock = this.lock;
|
ReentrantLock lock = this.lock;
|
||||||
@@ -439,9 +451,11 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
|
checkRange(from);
|
||||||
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
|
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||||
K[] a = ARRAYS.newArray(type, length);
|
K[] a = ARRAYS.newArray(type, length);
|
||||||
if(length <= 0) return a;
|
|
||||||
ReentrantLock lock = this.lock;
|
ReentrantLock lock = this.lock;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -449,9 +463,9 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
System.arraycopy(data, from, a, 0, length);
|
System.arraycopy(data, from, a, 0, length);
|
||||||
if(to == data.length) this.data = Arrays.copyOf(data, data.length - length);
|
if(to == data.length) this.data = Arrays.copyOf(data, data.length - length);
|
||||||
else {
|
else {
|
||||||
int size = data.length-1;
|
int size = data.length;
|
||||||
KEY_TYPE[] newElements = NEW_KEY_ARRAY(size);
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(size-length);
|
||||||
System.arraycopy(data, 0, newElements, 0, from);
|
if(from != 0) System.arraycopy(data, 0, newElements, 0, from);
|
||||||
System.arraycopy(data, to, newElements, from, size - to);
|
System.arraycopy(data, to, newElements, from, size - to);
|
||||||
this.data = newElements;
|
this.data = newElements;
|
||||||
}
|
}
|
||||||
@@ -471,6 +485,8 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
|
checkRange(from);
|
||||||
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
if(length <= 0) return EMPTY_KEY_ARRAY;
|
if(length <= 0) return EMPTY_KEY_ARRAY;
|
||||||
ReentrantLock lock = this.lock;
|
ReentrantLock lock = this.lock;
|
||||||
@@ -481,9 +497,9 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
System.arraycopy(data, from, a, 0, length);
|
System.arraycopy(data, from, a, 0, length);
|
||||||
if(to == data.length) this.data = Arrays.copyOf(data, data.length - length);
|
if(to == data.length) this.data = Arrays.copyOf(data, data.length - length);
|
||||||
else {
|
else {
|
||||||
int size = data.length-1;
|
int size = data.length;
|
||||||
KEY_TYPE[] newElements = NEW_KEY_ARRAY(size);
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(size-length);
|
||||||
System.arraycopy(data, 0, newElements, 0, from);
|
if(from != 0) System.arraycopy(data, 0, newElements, 0, from);
|
||||||
System.arraycopy(data, to, newElements, from, size - to);
|
System.arraycopy(data, to, newElements, from, size - to);
|
||||||
this.data = newElements;
|
this.data = newElements;
|
||||||
}
|
}
|
||||||
@@ -719,7 +735,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
SanityChecks.checkArrayCapacity(data.length, fromIndex, toIndex-fromIndex);
|
SanityChecks.checkArrayCapacity(data.length, fromIndex, toIndex-fromIndex);
|
||||||
return new COWSubListBRACES(this, 0, fromIndex, toIndex);
|
return new COWSubListBRACES(this, lock, this::setArray, this::getArray, 0, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1388,7 +1404,12 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PRIMITIVES
|
protected void checkAddRange(int index) {
|
||||||
|
if (index < 0 || index > data.length)
|
||||||
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PRIMITIVES
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@@ -1435,7 +1456,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return data[index--];
|
return data[--index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1458,7 +1479,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@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, (data.length - 1) - index);
|
int steps = Math.min(amount, data.length - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
@@ -1474,13 +1495,19 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
private static class COWSubList KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
private static class COWSubList KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
final COPY_ON_WRITE_LIST KEY_GENERIC_TYPE list;
|
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
|
final ReentrantLock lock;
|
||||||
|
final Consumer<KEY_TYPE[]> setter;
|
||||||
|
final Supplier<KEY_TYPE[]> getter;
|
||||||
final int parentOffset;
|
final int parentOffset;
|
||||||
final int offset;
|
final int offset;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
public COWSubList(COPY_ON_WRITE_LIST KEY_GENERIC_TYPE list, int offset, int from, int to) {
|
public COWSubList(ABSTRACT_LIST KEY_GENERIC_TYPE list, ReentrantLock lock, Consumer<KEY_TYPE[]> setter, Supplier<KEY_TYPE[]> getter, int offset, int from, int to) {
|
||||||
this.list = list;
|
this.list = list;
|
||||||
|
this.lock = lock;
|
||||||
|
this.setter = setter;
|
||||||
|
this.getter = getter;
|
||||||
this.parentOffset = from;
|
this.parentOffset = from;
|
||||||
this.offset = offset + from;
|
this.offset = offset + from;
|
||||||
this.size = to - from;
|
this.size = to - from;
|
||||||
@@ -1488,7 +1515,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(int index, KEY_TYPE element) {
|
public void add(int index, KEY_TYPE element) {
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkAddSubRange(index);
|
checkAddSubRange(index);
|
||||||
@@ -1504,7 +1530,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||||
int add = c.size();
|
int add = c.size();
|
||||||
if(add <= 0) return false;
|
if(add <= 0) return false;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkAddSubRange(index);
|
checkAddSubRange(index);
|
||||||
@@ -1521,7 +1546,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
int add = c.size();
|
int add = c.size();
|
||||||
if(add <= 0) return false;
|
if(add <= 0) return false;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkAddSubRange(index);
|
checkAddSubRange(index);
|
||||||
@@ -1538,7 +1562,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||||
int add = c.size();
|
int add = c.size();
|
||||||
if(add <= 0) return false;
|
if(add <= 0) return false;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkAddSubRange(index);
|
checkAddSubRange(index);
|
||||||
@@ -1554,7 +1577,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@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) {
|
||||||
if(length <= 0) return;
|
if(length <= 0) return;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkAddSubRange(from);
|
checkAddSubRange(from);
|
||||||
@@ -1570,17 +1592,16 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
SanityChecks.checkArrayCapacity(size, from, length);
|
SanityChecks.checkArrayCapacity(size, from, length);
|
||||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
return list.getElements(from+this.offset, a, offset, length);
|
return list.getElements(from+parentOffset, a, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeElements(int from, int to) {
|
public void removeElements(int from, int to) {
|
||||||
if(to-from <= 0) return;
|
if(to-from <= 0) return;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
list.removeElements(from+parentOffset, to+parentOffset);
|
list.removeElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= to - from;
|
||||||
}
|
}
|
||||||
@@ -1592,13 +1613,12 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -1609,13 +1629,12 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(from);
|
checkSubRange(from);
|
||||||
checkSubRange(to);
|
checkAddSubRange(to);
|
||||||
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -1627,16 +1646,15 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.GET_KEY(offset+index);
|
return list.GET_KEY(parentOffset+index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE element) {
|
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
return list.set(offset+index, element);
|
return list.set(parentOffset+index, element);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
@@ -1645,11 +1663,18 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE swapRemove(int index) {
|
public KEY_TYPE swapRemove(int index) {
|
||||||
ReentrantLock lock = list.lock;
|
if(index < 0 || index >= size) throw new IndexOutOfBoundsException();
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(index);
|
KEY_TYPE[] data = getter.get();
|
||||||
KEY_TYPE result = list.swapRemove(index+parentOffset);
|
KEY_TYPE result = data[offset+index];
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length-1);
|
||||||
|
int end = offset+size-1;
|
||||||
|
System.arraycopy(data, 0, newElements, 0, end);
|
||||||
|
if(end != newElements.length) System.arraycopy(data, end+1, newElements, end, data.length-end-1);
|
||||||
|
if(index+offset != end) newElements[index+offset] = data[end];
|
||||||
|
setter.accept(newElements);
|
||||||
size--;
|
size--;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1660,7 +1685,6 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) {
|
public KEY_TYPE REMOVE(int index) {
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkSubRange(index);
|
checkSubRange(index);
|
||||||
@@ -1673,6 +1697,371 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_KEY(KEY_TYPE type) {
|
||||||
|
int index = indexOf(type);
|
||||||
|
if(index == -1) return false;
|
||||||
|
REMOVE(index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object type) {
|
||||||
|
int index = indexOf(type);
|
||||||
|
if(index == -1) return false;
|
||||||
|
REMOVE(index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void sort(Comparator<? super CLASS_TYPE> c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
if(c != null) ARRAYS.stableSort(newData, offset, offset+size, c);
|
||||||
|
else ARRAYS.stableSort(newData, offset, offset+size);
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unstableSort(Comparator<? super CLASS_TYPE> c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
if(c != null) ARRAYS.unstableSort(newData, offset, offset+size, c);
|
||||||
|
else ARRAYS.unstableSort(newData, offset, offset+size);
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void sort(COMPARATOR c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
if(c != null) ARRAYS.stableSort(newData, offset, offset+size, c);
|
||||||
|
else ARRAYS.stableSort(newData, offset, offset+size);
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unstableSort(COMPARATOR c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
if(c != null) ARRAYS.unstableSort(newData, offset, offset+size, c);
|
||||||
|
else ARRAYS.unstableSort(newData, offset, offset+size);
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean removeAll(Collection<?> c) {
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(!c.contains(KEY_TO_OBJ(data[i]))) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean retainAll(Collection<?> c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
if(size > 0) {
|
||||||
|
clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(c.contains(KEY_TO_OBJ(data[i]))) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(!filter.test(KEY_TO_OBJ(data[i]))) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(!c.contains(data[i])) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(!c.contains(data[i])) newElements[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
if(size > 0) {
|
||||||
|
clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(c.contains(data[i])) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));;
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
if(size > 0) {
|
||||||
|
forEach(r);
|
||||||
|
clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i= 0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(c.contains(data[i])) newElements[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PRIMITIVES
|
||||||
|
@Override
|
||||||
|
public boolean remIf(JAVA_PREDICATE filter) {
|
||||||
|
Objects.requireNonNull(filter);
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newElements = NEW_KEY_ARRAY(data.length);
|
||||||
|
int j = 0;
|
||||||
|
for(int i=0,m=data.length;i<m;i++) {
|
||||||
|
if(i < offset || i >= offset+size) newElements[j++] = data[i];
|
||||||
|
else if(!filter.test(data[i])) newElements[j++] = data[i];
|
||||||
|
}
|
||||||
|
if(data.length != j) {
|
||||||
|
setter.accept(Arrays.copyOf(newElements, j));
|
||||||
|
size -= data.length - j;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public void replaceAll(UnaryOperator<CLASS_TYPE> o) {
|
||||||
|
#if PRIMITIVES
|
||||||
|
Objects.requireNonNull(o);
|
||||||
|
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||||
|
REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ(SanityChecks.SANITY_CAST(T)))));
|
||||||
|
#else
|
||||||
|
REPLACE(T -> OBJ_TO_KEY(o.apply(KEY_TO_OBJ(T))));
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
Objects.requireNonNull(o);
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
for(int i = 0,m=size;i<m;i++)
|
||||||
|
newData[i+offset] = OBJ_TO_KEY(o.apply(KEY_TO_OBJ(newData[i+offset])));
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PRIMITIVES
|
||||||
|
@Override
|
||||||
|
public void REPLACE(JAVA_UNARY_OPERATOR o) {
|
||||||
|
Objects.requireNonNull(o);
|
||||||
|
ReentrantLock lock = this.lock;
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
KEY_TYPE[] data = getter.get();
|
||||||
|
KEY_TYPE[] newData = Arrays.copyOf(data, data.length);
|
||||||
|
for(int i = 0,m=size;i<m;i++)
|
||||||
|
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||||
|
newData[i+offset] = SanityChecks.SANITY_CAST(o.APPLY_CAST(newData[i+offset]));
|
||||||
|
#else
|
||||||
|
newData[i+offset] = o.APPLY(newData[i+offset]);
|
||||||
|
#endif
|
||||||
|
setter.accept(newData);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return size;
|
return size;
|
||||||
@@ -1681,10 +2070,9 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if(size == 0) return;
|
if(size == 0) return;
|
||||||
ReentrantLock lock = list.lock;
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
list.removeElements(offset, offset+size);
|
list.removeElements(parentOffset, parentOffset+size);
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -1704,7 +2092,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||||
return new COWSubListBRACES(list, offset, fromIndex, toIndex);
|
return new COWSubListBRACES(this, lock, setter, getter, offset, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkSubRange(int index) {
|
protected void checkSubRange(int index) {
|
||||||
@@ -1772,7 +2160,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
|||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (list.size() - 1) - index);
|
int steps = Math.min(amount, list.size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -556,7 +556,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|||||||
+85
-72
@@ -152,10 +152,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
int length = c.size();
|
int length = c.size();
|
||||||
if(length == 0) return false;
|
if(length == 0) return false;
|
||||||
checkAddRange(index);
|
checkAddRange(index);
|
||||||
Entry KEY_GENERIC_TYPE next = null;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
Entry KEY_GENERIC_TYPE prev = null;
|
Entry KEY_GENERIC_TYPE prev;
|
||||||
if(index == size) prev = last;
|
if(index == size) {
|
||||||
else if(index == 0) next = first;
|
prev = last;
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
|
else if(index == 0) {
|
||||||
|
next = first;
|
||||||
|
prev = null;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
next = getNode(index);
|
next = getNode(index);
|
||||||
prev = next.prev;
|
prev = next.prev;
|
||||||
@@ -177,30 +183,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||||
int length = c.size();
|
return addAll(index, (COLLECTION KEY_GENERIC_TYPE)c); //
|
||||||
if(length == 0) return false;
|
|
||||||
checkAddRange(index);
|
|
||||||
Entry KEY_GENERIC_TYPE next = null;
|
|
||||||
Entry KEY_GENERIC_TYPE prev = null;
|
|
||||||
if(index == size) prev = last;
|
|
||||||
else if(index == 0) next = first;
|
|
||||||
else {
|
|
||||||
next = getNode(index);
|
|
||||||
prev = next.prev;
|
|
||||||
}
|
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();) {
|
|
||||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(iter.NEXT(), prev, null);
|
|
||||||
if(prev == null) first = entry;
|
|
||||||
else prev.next = entry;
|
|
||||||
prev = entry;
|
|
||||||
}
|
|
||||||
if(next == null) last = prev;
|
|
||||||
else {
|
|
||||||
prev.next = next;
|
|
||||||
next.prev = prev;
|
|
||||||
}
|
|
||||||
size += length;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -210,10 +193,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
int length = c.size();
|
int length = c.size();
|
||||||
if(length == 0) return false;
|
if(length == 0) return false;
|
||||||
checkAddRange(index);
|
checkAddRange(index);
|
||||||
Entry KEY_GENERIC_TYPE next = null;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
Entry KEY_GENERIC_TYPE prev = null;
|
Entry KEY_GENERIC_TYPE prev;
|
||||||
if(index == size) prev = last;
|
if(index == size) {
|
||||||
else if(index == 0) next = first;
|
prev = last;
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
|
else if(index == 0) {
|
||||||
|
next = first;
|
||||||
|
prev = null;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
next = getNode(index);
|
next = getNode(index);
|
||||||
prev = next.prev;
|
prev = next.prev;
|
||||||
@@ -258,12 +247,19 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@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) {
|
||||||
|
if(length <= 0) return;
|
||||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
checkAddRange(from);
|
checkAddRange(from);
|
||||||
Entry KEY_GENERIC_TYPE next = null;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
Entry KEY_GENERIC_TYPE prev = null;
|
Entry KEY_GENERIC_TYPE prev;
|
||||||
if(from == size) prev = last;
|
if(from == size) {
|
||||||
else if(from == 0) next = first;
|
prev = last;
|
||||||
|
next = null;
|
||||||
|
}
|
||||||
|
else if(from == 0) {
|
||||||
|
next = first;
|
||||||
|
prev = null;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
next = getNode(from);
|
next = getNode(from);
|
||||||
prev = next.prev;
|
prev = next.prev;
|
||||||
@@ -297,13 +293,13 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE first() {
|
public KEY_TYPE first() {
|
||||||
if(first == null) throw new IllegalStateException();
|
if(first == null) throw new NoSuchElementException();
|
||||||
return first.value;
|
return first.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE last() {
|
public KEY_TYPE last() {
|
||||||
if(last == null) throw new IllegalStateException();
|
if(last == null) throw new NoSuchElementException();
|
||||||
return last.value;
|
return last.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,13 +532,13 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE dequeue() {
|
public KEY_TYPE dequeue() {
|
||||||
if(first == null) throw new IllegalStateException();
|
if(first == null) throw new NoSuchElementException();
|
||||||
return unlinkFirst(first);
|
return unlinkFirst(first);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE dequeueLast() {
|
public KEY_TYPE dequeueLast() {
|
||||||
if(last == null) throw new IllegalStateException();
|
if(last == null) throw new NoSuchElementException();
|
||||||
return unlinkLast(last);
|
return unlinkLast(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,12 +589,15 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
first = temp;
|
first = temp;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Entry KEY_GENERIC_TYPE temp = last;
|
else if(before.next != last) {
|
||||||
last = temp.prev;
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
last.next = null;
|
last = temp.prev;
|
||||||
temp.next = before.next;
|
last.next = null;
|
||||||
temp.prev = before;
|
temp.next = before.next;
|
||||||
before.next = temp;
|
temp.prev = before;
|
||||||
|
before.next = temp;
|
||||||
|
temp.next.prev = temp;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,12 +622,15 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
first = temp;
|
first = temp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Entry KEY_GENERIC_TYPE temp = last;
|
else if(before.next != last) {
|
||||||
last = temp.prev;
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
last.next = null;
|
last = temp.prev;
|
||||||
temp.next = before.next;
|
last.next = null;
|
||||||
temp.prev = before;
|
temp.next = before.next;
|
||||||
before.next = temp;
|
temp.prev = before;
|
||||||
|
before.next = temp;
|
||||||
|
temp.next.prev = temp;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -671,16 +673,18 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
if(from < size - to) {
|
if(from < size - to) {
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||||
while(length > 0) {
|
while(length > 0) {
|
||||||
entry = entry.next;
|
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||||
unlink(entry.prev);
|
unlink(entry);
|
||||||
|
entry = next;
|
||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||||
while(length > 0) {
|
while(length > 0) {
|
||||||
entry = entry.prev;
|
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||||
unlink(entry.next);
|
unlink(entry);
|
||||||
|
entry = prev;
|
||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,20 +695,22 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
checkRange(from);
|
checkRange(from);
|
||||||
checkAddRange(to);
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
|
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||||
K[] a = ARRAYS.newArray(type, length);
|
K[] a = ARRAYS.newArray(type, length);
|
||||||
if(length <= 0) return a;
|
|
||||||
if(from < size - to) {
|
if(from < size - to) {
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||||
for(int i = 0;length > 0;i++, length--) {
|
for(int i = 0;length > 0;i++, length--) {
|
||||||
entry = entry.next;
|
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||||
a[i] = (K)unlink(entry.prev);
|
a[i] = (K)unlink(entry);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||||
for(int i = length-1;length > 0;i--) {
|
for(int i = length-1;length > 0;i--, length--) {
|
||||||
entry = entry.prev;
|
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||||
a[i] = (K)unlink(entry.next);
|
a[i] = (K)unlink(entry);
|
||||||
|
entry = prev;
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -720,15 +726,17 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
if(from < size - to) {
|
if(from < size - to) {
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||||
for(int i = 0;length > 0;i++, length--) {
|
for(int i = 0;length > 0;i++, length--) {
|
||||||
entry = entry.next;
|
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||||
d[i] = unlink(entry.prev);
|
d[i] = unlink(entry);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||||
for(int i = length-1;length > 0;i--) {
|
for(int i = length-1;length > 0;i--, length--) {
|
||||||
entry = entry.prev;
|
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||||
d[i] = unlink(entry.next);
|
d[i] = unlink(entry);
|
||||||
|
entry = prev;
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
@@ -1106,6 +1114,11 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
this.prev = prev;
|
this.prev = prev;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return KEY_TO_STRING(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ListIter implements LIST_ITERATOR KEY_GENERIC_TYPE
|
private class ListIter implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||||
@@ -1239,7 +1252,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long estimateSize() {
|
public long estimateSize() {
|
||||||
return list.size - index;
|
return (long)list.size - (long)index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1305,7 +1318,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long estimateSize() {
|
public long estimateSize() {
|
||||||
return list.size - index;
|
return (long)list.size - (long)index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+15
-1
@@ -285,6 +285,16 @@ 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);
|
||||||
@@ -306,7 +316,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
|
||||||
|
|||||||
+40
-3
@@ -73,6 +73,7 @@ import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
|||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
import speiger.src.collections.objects.sets.ObjectSet;
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TypeSpecific ConcurrentHashMap implementation that is based on <a href="https://github.com/google/guava">Guavas</a> approach and backing array implementations.
|
* A TypeSpecific ConcurrentHashMap implementation that is based on <a href="https://github.com/google/guava">Guavas</a> approach and backing array implementations.
|
||||||
@@ -84,7 +85,7 @@ import speiger.src.collections.utils.HashUtil;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE
|
public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE, ITrimmable
|
||||||
{
|
{
|
||||||
/** Segment Limit */
|
/** Segment Limit */
|
||||||
private static final int MAX_SEGMENTS = 1 << 16;
|
private static final int MAX_SEGMENTS = 1 << 16;
|
||||||
@@ -538,6 +539,30 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean trim(int size) {
|
||||||
|
int segmentCapacity = size / segments.length;
|
||||||
|
if(segmentCapacity * segments.length < size) {
|
||||||
|
segmentCapacity++;
|
||||||
|
}
|
||||||
|
boolean result = false;
|
||||||
|
for(int i = 0, m=segments.length;i<m;i++) {
|
||||||
|
result |= segments[i].trim(segmentCapacity);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAndTrim(int size) {
|
||||||
|
int segmentCapacity = size / segments.length;
|
||||||
|
if(segmentCapacity * segments.length < size) {
|
||||||
|
segmentCapacity++;
|
||||||
|
}
|
||||||
|
for(int i = 0, m=segments.length;i<m;i++) {
|
||||||
|
segments[i].clearAndTrim(segmentCapacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
for(int i = 0,m=segments.length;i<m;i++) {
|
for(int i = 0,m=segments.length;i<m;i++) {
|
||||||
@@ -1787,6 +1812,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
insert(-slot-1, key, value);
|
insert(-slot-1, key, value);
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||||
|
VALUE_TYPE oldValue = values[slot];
|
||||||
|
values[slot] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
return values[slot];
|
return values[slot];
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -2025,7 +2055,11 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
long stamp = writeLock();
|
long stamp = writeLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(key == null) {
|
if(key == null) {
|
||||||
|
#else
|
||||||
|
if(key == null || (key instanceof CLASS_TYPE && KEY_EQUALS_NULL(CLASS_TO_KEY(key)))) {
|
||||||
|
#endif
|
||||||
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
||||||
removeNullIndex();
|
removeNullIndex();
|
||||||
return true;
|
return true;
|
||||||
@@ -2202,7 +2236,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
|
|
||||||
protected boolean trim(int size) {
|
protected boolean trim(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 || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
if(request >= mask+1 || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||||
long stamp = writeLock();
|
long stamp = writeLock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
@@ -2218,7 +2252,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
|
|
||||||
protected void clearAndTrim(int size) {
|
protected 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 >= mask+1) {
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2298,6 +2332,9 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
|||||||
#endif
|
#endif
|
||||||
protected int findIndex(int hash, Object key) {
|
protected int findIndex(int hash, Object key) {
|
||||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(KEY_EQUALS_NULL(CLASS_TO_KEY(key))) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#endif
|
||||||
int pos = hash & mask;
|
int pos = hash & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
|
|||||||
+10
-13
@@ -22,7 +22,6 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
|
||||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
@@ -57,7 +56,7 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
|||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
|
|
||||||
@@ -285,7 +284,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToFirst(KEY_TYPE key) {
|
public boolean moveToFirst(KEY_TYPE key) {
|
||||||
if(strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToFirstIndex(nullIndex);
|
moveToFirstIndex(nullIndex);
|
||||||
@@ -307,7 +306,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToLast(KEY_TYPE key) {
|
public boolean moveToLast(KEY_TYPE key) {
|
||||||
if(strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
if(isEmpty() || strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
||||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToLastIndex(nullIndex);
|
moveToLastIndex(nullIndex);
|
||||||
@@ -370,8 +369,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_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)) {
|
||||||
@@ -394,8 +392,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_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)) {
|
||||||
@@ -421,15 +418,15 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
if(entrySet == null) entrySet = new MapEntrySet();
|
if(entrySet == null) entrySet = new MapEntrySet();
|
||||||
return entrySet;
|
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keySet == null) keySet = new KeySet();
|
if(keySet == null) keySet = new KeySet();
|
||||||
return keySet;
|
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -456,7 +453,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
@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;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-5
@@ -270,6 +270,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
insert(-slot-1, key, value);
|
insert(-slot-1, key, value);
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||||
|
VALUE_TYPE oldValue = values[slot];
|
||||||
|
values[slot] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
return values[slot];
|
return values[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +399,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object key, Object value) {
|
public boolean remove(Object key, Object value) {
|
||||||
Objects.requireNonNull(value);
|
Objects.requireNonNull(value);
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(key == null) {
|
if(key == null) {
|
||||||
|
#else
|
||||||
|
if(key == null || (key instanceof CLASS_TYPE && strategy.equals(CLASS_TO_KEY(key), EMPTY_KEY_VALUE))) {
|
||||||
|
#endif
|
||||||
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
||||||
removeNullIndex();
|
removeNullIndex();
|
||||||
return true;
|
return true;
|
||||||
@@ -628,7 +637,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
public boolean trim(int size) {
|
public boolean trim(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 || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
if(request >= nullIndex || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||||
try {
|
try {
|
||||||
rehash(request);
|
rehash(request);
|
||||||
}
|
}
|
||||||
@@ -639,7 +648,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@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;
|
||||||
}
|
}
|
||||||
@@ -669,6 +678,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
protected int findIndex(CLASS_TYPE key) {
|
protected int findIndex(CLASS_TYPE key) {
|
||||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
KEY_TYPE keyType = CLASS_TO_KEY(key);
|
KEY_TYPE keyType = CLASS_TO_KEY(key);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(strategy.equals(keyType, EMPTY_KEY_VALUE)) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(strategy.hashCode(keyType)) & mask;
|
int pos = HashUtil.mix(strategy.hashCode(keyType)) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
||||||
@@ -942,7 +954,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
@@ -1173,7 +1185,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
state = keys[nullIndex];
|
state = keys[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
@@ -1329,7 +1341,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
state = values[nullIndex];
|
state = values[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
|
|||||||
+10
-13
@@ -22,7 +22,6 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||||
@@ -56,7 +55,7 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
|||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
|
|
||||||
@@ -262,7 +261,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToFirst(KEY_TYPE key) {
|
public boolean moveToFirst(KEY_TYPE key) {
|
||||||
if(KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||||
if(KEY_EQUALS_NULL(key)) {
|
if(KEY_EQUALS_NULL(key)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToFirstIndex(nullIndex);
|
moveToFirstIndex(nullIndex);
|
||||||
@@ -284,7 +283,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveToLast(KEY_TYPE key) {
|
public boolean moveToLast(KEY_TYPE key) {
|
||||||
if(KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
if(isEmpty() || KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
||||||
if(KEY_EQUALS_NULL(key)) {
|
if(KEY_EQUALS_NULL(key)) {
|
||||||
if(containsNull) {
|
if(containsNull) {
|
||||||
moveToLastIndex(nullIndex);
|
moveToLastIndex(nullIndex);
|
||||||
@@ -374,8 +373,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_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)) {
|
||||||
@@ -398,8 +396,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_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)) {
|
||||||
@@ -425,15 +422,15 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
if(entrySet == null) entrySet = new MapEntrySet();
|
if(entrySet == null) entrySet = new MapEntrySet();
|
||||||
return entrySet;
|
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keySet == null) keySet = new KeySet();
|
if(keySet == null) keySet = new KeySet();
|
||||||
return keySet;
|
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -460,7 +457,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
@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;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-5
@@ -245,6 +245,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
insert(-slot-1, key, value);
|
insert(-slot-1, key, value);
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
else if(VALUE_EQUALS(values[slot], getDefaultReturnValue())) {
|
||||||
|
VALUE_TYPE oldValue = values[slot];
|
||||||
|
values[slot] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
return values[slot];
|
return values[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +367,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object key, Object value) {
|
public boolean remove(Object key, Object value) {
|
||||||
Objects.requireNonNull(value);
|
Objects.requireNonNull(value);
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(key == null) {
|
if(key == null) {
|
||||||
|
#else
|
||||||
|
if(key == null || (key instanceof CLASS_TYPE && KEY_EQUALS_NULL(CLASS_TO_KEY(key)))) {
|
||||||
|
#endif
|
||||||
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
||||||
removeNullIndex();
|
removeNullIndex();
|
||||||
return true;
|
return true;
|
||||||
@@ -589,7 +598,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
public boolean trim(int size) {
|
public boolean trim(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 || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||||
try {
|
try {
|
||||||
rehash(request);
|
rehash(request);
|
||||||
}
|
}
|
||||||
@@ -600,7 +609,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@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;
|
||||||
}
|
}
|
||||||
@@ -629,6 +638,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
#endif
|
#endif
|
||||||
protected int findIndex(Object key) {
|
protected int findIndex(Object key) {
|
||||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(key instanceof CLASS_TYPE && KEY_EQUALS_NULL(CLASS_TO_KEY(key))) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(key.hashCode()) & mask;
|
int pos = HashUtil.mix(key.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
@@ -902,7 +914,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
@@ -1129,7 +1141,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
state = keys[nullIndex];
|
state = keys[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
@@ -1285,7 +1297,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
state = values[nullIndex];
|
state = values[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
|
|||||||
+10
-6
@@ -25,7 +25,9 @@ import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
@@ -47,7 +49,6 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
|||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
|
||||||
#endif
|
#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;
|
||||||
@@ -70,7 +71,7 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
|||||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
@@ -100,9 +101,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
/** The Last Index in the Map */
|
/** The Last Index in the Map */
|
||||||
protected int lastIndex = -1;
|
protected int lastIndex = -1;
|
||||||
/** EntrySet cache */
|
/** EntrySet cache */
|
||||||
protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet;
|
protected transient FastOrderedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||||
/** KeySet cache */
|
/** KeySet cache */
|
||||||
protected transient SET KEY_GENERIC_TYPE keySet;
|
protected transient ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||||
/** Values cache */
|
/** Values cache */
|
||||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||||
|
|
||||||
@@ -429,13 +430,13 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
if(entrySet == null) entrySet = new MapEntrySet();
|
if(entrySet == null) entrySet = new MapEntrySet();
|
||||||
return entrySet;
|
return entrySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keySet == null) keySet = new KeySet();
|
if(keySet == null) keySet = new KeySet();
|
||||||
return keySet;
|
return keySet;
|
||||||
}
|
}
|
||||||
@@ -516,6 +517,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
#endif
|
#endif
|
||||||
protected int findIndex(Object key) {
|
protected int findIndex(Object key) {
|
||||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(KEY_EQUALS_NULL(CLASS_TO_KEY(key))) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(key.hashCode()) & mask;
|
int pos = HashUtil.mix(key.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
|
|||||||
+20
-10
@@ -27,7 +27,6 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
@@ -90,7 +89,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
/** Amount of Elements stored in the ArrayMap */
|
/** Amount of Elements stored in the ArrayMap */
|
||||||
protected int size = 0;
|
protected int size = 0;
|
||||||
/** KeySet cache */
|
/** KeySet cache */
|
||||||
protected SET KEY_GENERIC_TYPE keySet;
|
protected ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||||
/** Values cache */
|
/** Values cache */
|
||||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||||
/** EntrySet cache */
|
/** EntrySet cache */
|
||||||
@@ -203,6 +202,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
insertIndex(size++, key, value);
|
insertIndex(size++, key, value);
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
else if(VALUE_EQUALS(values[index], getDefaultReturnValue())) {
|
||||||
|
VALUE_TYPE oldValue = values[index];
|
||||||
|
values[index] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
return values[index];
|
return values[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +274,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
@Override
|
@Override
|
||||||
public boolean moveToLast(KEY_TYPE key) {
|
public boolean moveToLast(KEY_TYPE key) {
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < size-1) {
|
if(index >= 0 && index < size-1) {
|
||||||
moveIndexToLast(index);
|
moveIndexToLast(index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -437,7 +441,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keySet == null) keySet = new KeySet();
|
if(keySet == null) keySet = new KeySet();
|
||||||
return keySet;
|
return keySet;
|
||||||
}
|
}
|
||||||
@@ -1234,6 +1238,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
public EntryIterator() {}
|
public EntryIterator() {}
|
||||||
public EntryIterator(KEY_TYPE from) {
|
public EntryIterator(KEY_TYPE from) {
|
||||||
index = findIndex(from);
|
index = findIndex(from);
|
||||||
|
if(index == -1) throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1249,7 +1254,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
entry.index = -1;
|
if(entry != null && entry.index != -1) {
|
||||||
|
entry.index = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1262,7 +1269,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
public KeyIterator() {}
|
public KeyIterator() {}
|
||||||
public KeyIterator(KEY_TYPE element) {
|
public KeyIterator(KEY_TYPE element) {
|
||||||
index = findIndex(element);
|
index = findIndex(element);
|
||||||
|
if(index == -1) throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
return keys[previousEntry()];
|
return keys[previousEntry()];
|
||||||
@@ -1319,8 +1328,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
removeIndex(lastReturned);
|
removeIndex(lastReturned);
|
||||||
if(lastReturned < index)
|
if(lastReturned < index)
|
||||||
index--;
|
index--;
|
||||||
@@ -1329,8 +1337,8 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
|
|
||||||
public int previousEntry() {
|
public int previousEntry() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = index;
|
index--;
|
||||||
return index--;
|
return (lastReturned = index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int nextEntry() {
|
public int nextEntry() {
|
||||||
@@ -1341,8 +1349,9 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1350,6 +1359,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-5
@@ -4,6 +4,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
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;
|
||||||
@@ -76,8 +77,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
keyType = keys[0].getDeclaringClass();
|
keyType = keys[0].getDeclaringClass();
|
||||||
this.keys = getKeyUniverse(keyType);
|
this.keys = getKeyUniverse(keyType);
|
||||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
present = new long[((keys.length - 1) >> 6) + 1];
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
putAll(keys, values);
|
putAll(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +94,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
keyType = keys[0].getDeclaringClass();
|
keyType = keys[0].getDeclaringClass();
|
||||||
this.keys = getKeyUniverse(keyType);
|
this.keys = getKeyUniverse(keyType);
|
||||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
present = new long[((keys.length - 1) >> 6) + 1];
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
putAll(keys, values);
|
putAll(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +161,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE putIfAbsent(T key, VALUE_TYPE value) {
|
public VALUE_TYPE putIfAbsent(T key, VALUE_TYPE value) {
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
if(isSet(index)) return values[index];
|
if(isSet(index)) {
|
||||||
|
if(VALUE_EQUALS(values[index], getDefaultReturnValue())) {
|
||||||
|
VALUE_TYPE oldValue = values[index];
|
||||||
|
values[index] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
return values[index];
|
||||||
|
}
|
||||||
set(index);
|
set(index);
|
||||||
values[index] = value;
|
values[index] = value;
|
||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
@@ -530,6 +538,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||||
|
if(size() <= 0) return;
|
||||||
|
for(int i = 0,m=keys.length;i<m;i++) {
|
||||||
|
if(isSet(i)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||||
return new EntryIterator();
|
return new EntryIterator();
|
||||||
|
|||||||
+13
-14
@@ -17,7 +17,6 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||||
@@ -29,7 +28,6 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
|||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,9 +66,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
keyType = keys[0].getDeclaringClass();
|
keyType = keys[0].getDeclaringClass();
|
||||||
this.keys = getKeyUniverse(keyType);
|
this.keys = getKeyUniverse(keyType);
|
||||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
present = new long[((keys.length - 1) >> 6) + 1];
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
links = new long[keys.length];
|
links = new long[this.keys.length];
|
||||||
putAll(keys, values);
|
putAll(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +84,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
keyType = keys[0].getDeclaringClass();
|
keyType = keys[0].getDeclaringClass();
|
||||||
this.keys = getKeyUniverse(keyType);
|
this.keys = getKeyUniverse(keyType);
|
||||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
present = new long[((keys.length - 1) >> 6) + 1];
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
links = new long[keys.length];
|
links = new long[this.keys.length];
|
||||||
putAll(keys, values);
|
putAll(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +239,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getAndMoveToFirst(T key) {
|
public VALUE_TYPE getAndMoveToFirst(T key) {
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
if(index < 0) return getDefaultReturnValue();
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
moveToFirstIndex(index);
|
moveToFirstIndex(index);
|
||||||
return values[index];
|
return values[index];
|
||||||
}
|
}
|
||||||
@@ -249,7 +247,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getAndMoveToLast(T key) {
|
public VALUE_TYPE getAndMoveToLast(T key) {
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
if(index < 0) return getDefaultReturnValue();
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
moveToLastIndex(index);
|
moveToLastIndex(index);
|
||||||
return values[index];
|
return values[index];
|
||||||
}
|
}
|
||||||
@@ -315,15 +313,15 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
if(entrySet == null) entrySet = new MapEntrySet();
|
if(entrySet == null) entrySet = new MapEntrySet();
|
||||||
return entrySet;
|
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keySet == null) keySet = new KeySet();
|
if(keySet == null) keySet = new KeySet();
|
||||||
return keySet;
|
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -830,6 +828,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
previous = from.ordinal() - 1;
|
previous = from.ordinal() - 1;
|
||||||
index = from.ordinal();
|
index = from.ordinal();
|
||||||
next = from.ordinal();
|
next = from.ordinal();
|
||||||
|
if(!isSet(index)) throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
|
|||||||
+160
-57
@@ -30,8 +30,9 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
#if TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
@@ -279,7 +280,10 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
int compare = 0;
|
int compare = 0;
|
||||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||||
while(true) {
|
while(true) {
|
||||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
if((compare = compare(key, parent.key)) == 0) {
|
||||||
|
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||||
|
return parent.value;
|
||||||
|
}
|
||||||
if(compare < 0) {
|
if(compare < 0) {
|
||||||
if(parent.left == null) break;
|
if(parent.left == null) break;
|
||||||
parent = parent.left;
|
parent = parent.left;
|
||||||
@@ -408,7 +412,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMinValue();
|
||||||
KEY_TYPE result = first.key;
|
KEY_TYPE result = first.key;
|
||||||
removeNode(first);
|
removeNode(first);
|
||||||
return result;
|
return result;
|
||||||
@@ -422,7 +426,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMaxValue();
|
||||||
KEY_TYPE result = last.key;
|
KEY_TYPE result = last.key;
|
||||||
removeNode(last);
|
removeNode(last);
|
||||||
return result;
|
return result;
|
||||||
@@ -682,7 +686,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
return navigableKeySet();
|
return navigableKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1022,6 +1026,33 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE lower(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE floor(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE higher(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE ceiling(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -1447,7 +1478,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
return navigableKeySet();
|
return navigableKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1461,8 +1492,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
||||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
|
||||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
||||||
|
|
||||||
@@ -1533,7 +1564,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMinValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1544,19 +1575,21 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMaxValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
||||||
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
||||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
if(entry == null) throw new NoSuchElementException();
|
||||||
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
||||||
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
||||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
if(entry == null) throw new NoSuchElementException();
|
||||||
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1632,7 +1665,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
||||||
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
|
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT && VALUE_OBJECT
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
@@ -1778,7 +1811,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
KEY_TYPE key = entry.ENTRY_KEY();
|
KEY_TYPE key = entry.ENTRY_KEY();
|
||||||
if (!inRange(key)) return false;
|
if (!inRange(key)) return false;
|
||||||
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
||||||
if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) {
|
if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) {
|
||||||
map.removeNode(node);
|
map.removeNode(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2023,26 +2056,36 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||||
{
|
{
|
||||||
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry();
|
return previousEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry();
|
return nextEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||||
{
|
{
|
||||||
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2061,26 +2104,36 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry().key;
|
return previousEntry().key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().key;
|
return nextEntry().key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2099,7 +2152,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2118,39 +2171,60 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry().value;
|
return previousEntry().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE VALUE_NEXT() {
|
public VALUE_TYPE VALUE_NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().value;
|
return nextEntry().value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SubMapEntryIterator
|
abstract class SubMapEntryIterator
|
||||||
{
|
{
|
||||||
|
final boolean isForward;
|
||||||
boolean wasForward;
|
boolean wasForward;
|
||||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||||
Node KEY_VALUE_GENERIC_TYPE next;
|
Node KEY_VALUE_GENERIC_TYPE next;
|
||||||
|
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
KEY_TYPE forwardFence;
|
KEY_TYPE forwardFence;
|
||||||
KEY_TYPE backwardFence;
|
KEY_TYPE backwardFence;
|
||||||
|
|
||||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence, boolean isForward) {
|
||||||
{
|
|
||||||
next = first;
|
next = first;
|
||||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
previous = first == null ? null : movePrevious(first);
|
||||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
unboundBackwardFence = backwardFence == null;
|
unboundBackwardFence = backwardFence == null;
|
||||||
|
this.isForward = isForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -2159,26 +2233,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||||
next = next.next();
|
next = moveNext(next);
|
||||||
wasForward = true;
|
wasForward = isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
next = previous;
|
||||||
next = next.previous();
|
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||||
wasForward = false;
|
previous = movePrevious(previous);
|
||||||
|
wasForward = !isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(next == lastReturned) next = moveNext(next);
|
||||||
|
if(previous == lastReturned) previous = movePrevious(previous);
|
||||||
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
map.removeNode(lastReturned);
|
map.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -2492,19 +2570,29 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, false);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE PREVIOUS() {
|
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
|
||||||
return nextEntry().key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
return previousEntry().key;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().key;
|
return nextEntry().key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2512,7 +2600,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
{
|
{
|
||||||
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2531,7 +2619,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2550,7 +2638,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2568,13 +2656,24 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
abstract class MapEntryIterator
|
abstract class MapEntryIterator
|
||||||
{
|
{
|
||||||
|
final boolean isForward;
|
||||||
boolean wasMoved = false;
|
boolean wasMoved = false;
|
||||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||||
Node KEY_VALUE_GENERIC_TYPE next;
|
Node KEY_VALUE_GENERIC_TYPE next;
|
||||||
|
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||||
|
|
||||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, boolean isForward) {
|
||||||
{
|
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : movePrevious(first);
|
||||||
|
this.isForward = isForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -2583,26 +2682,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
|||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||||
next = next.next();
|
next = moveNext(next);
|
||||||
wasMoved = true;
|
wasMoved = isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
next = previous;
|
||||||
next = next.previous();
|
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||||
wasMoved = false;
|
previous = movePrevious(previous);
|
||||||
|
wasMoved = !isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(next == lastReturned) next = moveNext(next);
|
||||||
|
if(previous == lastReturned) previous = movePrevious(previous);
|
||||||
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
|
|||||||
+170
-57
@@ -30,8 +30,9 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
#if TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
@@ -279,7 +280,10 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
int compare = 0;
|
int compare = 0;
|
||||||
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
Node KEY_VALUE_GENERIC_TYPE parent = tree;
|
||||||
while(true) {
|
while(true) {
|
||||||
if((compare = compare(key, parent.key)) == 0) return parent.value;
|
if((compare = compare(key, parent.key)) == 0) {
|
||||||
|
if(VALUE_EQUALS(parent.value, getDefaultReturnValue())) return parent.setValue(value);
|
||||||
|
return parent.value;
|
||||||
|
}
|
||||||
if(compare < 0) {
|
if(compare < 0) {
|
||||||
if(parent.left == null) break;
|
if(parent.left == null) break;
|
||||||
parent = parent.left;
|
parent = parent.left;
|
||||||
@@ -411,7 +415,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMinValue();
|
||||||
KEY_TYPE result = first.key;
|
KEY_TYPE result = first.key;
|
||||||
removeNode(first);
|
removeNode(first);
|
||||||
return result;
|
return result;
|
||||||
@@ -425,7 +429,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMaxValue();
|
||||||
KEY_TYPE result = last.key;
|
KEY_TYPE result = last.key;
|
||||||
removeNode(last);
|
removeNode(last);
|
||||||
return result;
|
return result;
|
||||||
@@ -685,7 +689,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
return navigableKeySet();
|
return navigableKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1080,6 +1084,33 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE lower(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE floor(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE higher(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CLASS_TYPE ceiling(CLASS_TYPE e) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
|
||||||
|
return node != null ? node.getKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -1283,6 +1314,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
return keySet;
|
return keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
|
return navigableKeySet();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
||||||
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
||||||
@@ -1369,6 +1405,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
return keySet;
|
return keySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
|
return navigableKeySet();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
||||||
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
||||||
@@ -1504,7 +1545,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||||
return navigableKeySet();
|
return navigableKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1518,8 +1559,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
||||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
|
||||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
||||||
|
|
||||||
@@ -1590,7 +1631,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMinValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1601,19 +1642,21 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMaxValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
||||||
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
||||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
if(entry == null) throw new NoSuchElementException();
|
||||||
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
||||||
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
||||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
if(entry == null) throw new NoSuchElementException();
|
||||||
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1689,7 +1732,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
||||||
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
|
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT && VALUE_OBJECT
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
@@ -1835,7 +1878,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
KEY_TYPE key = entry.ENTRY_KEY();
|
KEY_TYPE key = entry.ENTRY_KEY();
|
||||||
if (!inRange(key)) return false;
|
if (!inRange(key)) return false;
|
||||||
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
||||||
if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) {
|
if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) {
|
||||||
map.removeNode(node);
|
map.removeNode(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2080,26 +2123,36 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||||
{
|
{
|
||||||
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry();
|
return previousEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry();
|
return nextEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||||
{
|
{
|
||||||
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2118,26 +2171,36 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry().key;
|
return previousEntry().key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().key;
|
return nextEntry().key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2156,7 +2219,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2175,39 +2238,60 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||||
super(first, forwardFence, backwardFence);
|
super(first, forwardFence, backwardFence, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return nextEntry().value;
|
return previousEntry().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE VALUE_NEXT() {
|
public VALUE_TYPE VALUE_NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().value;
|
return nextEntry().value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SubMapEntryIterator
|
abstract class SubMapEntryIterator
|
||||||
{
|
{
|
||||||
|
final boolean isForward;
|
||||||
boolean wasForward;
|
boolean wasForward;
|
||||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||||
Node KEY_VALUE_GENERIC_TYPE next;
|
Node KEY_VALUE_GENERIC_TYPE next;
|
||||||
|
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
KEY_TYPE forwardFence;
|
KEY_TYPE forwardFence;
|
||||||
KEY_TYPE backwardFence;
|
KEY_TYPE backwardFence;
|
||||||
|
|
||||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence, boolean isForward) {
|
||||||
{
|
|
||||||
next = first;
|
next = first;
|
||||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
previous = first == null ? null : movePrevious(first);
|
||||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
unboundBackwardFence = backwardFence == null;
|
unboundBackwardFence = backwardFence == null;
|
||||||
|
this.isForward = isForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -2216,26 +2300,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||||
next = next.next();
|
next = moveNext(next);
|
||||||
wasForward = true;
|
wasForward = isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
next = previous;
|
||||||
next = next.previous();
|
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||||
wasForward = false;
|
previous = movePrevious(previous);
|
||||||
|
wasForward = !isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(next == lastReturned) next = moveNext(next);
|
||||||
|
if(previous == lastReturned) previous = movePrevious(previous);
|
||||||
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
map.removeNode(lastReturned);
|
map.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -2549,19 +2637,29 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, false);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE PREVIOUS() {
|
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
|
||||||
return nextEntry().key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
return previousEntry().key;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return previousEntry().key;
|
return nextEntry().key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2569,7 +2667,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
{
|
{
|
||||||
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2588,7 +2686,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2607,7 +2705,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||||
super(first);
|
super(first, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2625,13 +2723,24 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
abstract class MapEntryIterator
|
abstract class MapEntryIterator
|
||||||
{
|
{
|
||||||
|
final boolean isForward;
|
||||||
boolean wasMoved = false;
|
boolean wasMoved = false;
|
||||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||||
Node KEY_VALUE_GENERIC_TYPE next;
|
Node KEY_VALUE_GENERIC_TYPE next;
|
||||||
|
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||||
|
|
||||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, boolean isForward) {
|
||||||
{
|
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : movePrevious(first);
|
||||||
|
this.isForward = isForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||||
|
return node.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
@@ -2640,26 +2749,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||||
next = next.next();
|
next = moveNext(next);
|
||||||
wasMoved = true;
|
wasMoved = isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
next = previous;
|
||||||
next = next.previous();
|
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||||
wasMoved = false;
|
previous = movePrevious(previous);
|
||||||
|
wasMoved = !isForward;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(next == lastReturned) next = moveNext(next);
|
||||||
|
if(previous == lastReturned) previous = movePrevious(previous);
|
||||||
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
|
|||||||
+22
-1
@@ -102,6 +102,26 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
*/
|
*/
|
||||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
|
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper method that allows to put int a MAP.Entry into a map.
|
||||||
|
* @param entry then Entry that should be inserted.
|
||||||
|
* @return the last present value or default return value.
|
||||||
|
*/
|
||||||
|
public default VALUE_TYPE put(Entry KEY_VALUE_GENERIC_TYPE entry) {
|
||||||
|
return put(entry.ENTRY_KEY(), entry.ENTRY_VALUE());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Helper method that allows to put int a Map.Entry into a map.
|
||||||
|
* @param entry then Entry that should be inserted.
|
||||||
|
* @return the last present value or default return value.
|
||||||
|
*/
|
||||||
|
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
|
||||||
|
return put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
|
* Type Specific array method to bulk add elements into a map without creating a wrapper and increasing performances
|
||||||
* @param keys the keys that should be added
|
* @param keys the keys that should be added
|
||||||
@@ -557,8 +577,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
*/
|
*/
|
||||||
public KEY_TYPE ENTRY_KEY();
|
public KEY_TYPE ENTRY_KEY();
|
||||||
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
/**
|
/**
|
||||||
* Type Specific getValue method that reduces boxing/unboxing
|
* Type Specific getValue method that reduces boxing/unboxing
|
||||||
@@ -1381,6 +1401,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
* @param initialSize the requested start capacity
|
* @param initialSize the requested start capacity
|
||||||
*/
|
*/
|
||||||
public BuilderCache(int initialSize) {
|
public BuilderCache(int initialSize) {
|
||||||
|
if(initialSize < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||||
keys = NEW_KEY_ARRAY(initialSize);
|
keys = NEW_KEY_ARRAY(initialSize);
|
||||||
values = NEW_VALUE_ARRAY(initialSize);
|
values = NEW_VALUE_ARRAY(initialSize);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -34,7 +34,9 @@ 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();
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped NavigableMap that is Synchronized
|
* Creates a Wrapped NavigableMap that is Synchronized
|
||||||
* @return a new NavigableMap that is synchronized
|
* @return a new NavigableMap that is synchronized
|
||||||
|
|||||||
+7
@@ -1,6 +1,9 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +97,10 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Wrapped SortedMap that is Synchronized
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
|||||||
+7
-5
@@ -9,9 +9,11 @@ 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;
|
||||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +33,7 @@ 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();
|
||||||
|
|
||||||
@@ -155,11 +157,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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-4
@@ -106,10 +106,15 @@ 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
|
||||||
@@ -152,9 +157,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();
|
||||||
index += first;
|
index += first;
|
||||||
return index > array.length ? array[index-array.length] : array[index];
|
return index >= array.length ? array[index-array.length] : array[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -429,6 +434,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;
|
||||||
|
|||||||
+2
-1
@@ -187,7 +187,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, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), 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;
|
||||||
@@ -414,6 +414,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -207,7 +207,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, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), 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);
|
||||||
}
|
}
|
||||||
@@ -389,6 +389,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-27
@@ -888,15 +888,11 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMaxValue() { return super.getDefaultMinValue(); }
|
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMinValue() { return super.getDefaultMaxValue(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||||
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
||||||
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
||||||
return new DescendingSubSetBRACES(set, false, fromElement, fromInclusive, false, toElement, toInclusive);
|
return new DescendingSubSetBRACES(set, false, toElement, toInclusive, false, fromElement, fromInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -973,21 +969,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
@@ -1298,6 +1288,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
@@ -1307,6 +1298,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.previous();
|
||||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
@@ -1322,6 +1314,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.next();
|
next = next.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
@@ -1330,15 +1323,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.previous();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1346,6 +1340,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(previous == lastReturned) previous = previous.previous();
|
||||||
|
if(next == lastReturned) next = next.next();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
set.removeNode(lastReturned);
|
set.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1356,6 +1352,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
@@ -1365,6 +1362,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.next();
|
||||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
@@ -1380,6 +1378,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.previous();
|
next = next.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
@@ -1388,15 +1387,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.next();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1404,6 +1404,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(previous == lastReturned) previous = previous.next();
|
||||||
|
if(next == lastReturned) next = next.previous();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
set.removeNode(lastReturned);
|
set.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1415,11 +1417,13 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
|
|
||||||
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1431,6 +1435,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.next();
|
next = next.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
@@ -1439,15 +1444,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.previous();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1455,6 +1461,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(lastReturned == previous) previous = previous.previous();
|
||||||
|
if(lastReturned == next) next = next.next();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1465,11 +1473,13 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
|
|
||||||
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1481,6 +1491,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.previous();
|
next = next.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
@@ -1489,15 +1500,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.next();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1505,6 +1517,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(lastReturned == previous) previous = previous.next();
|
||||||
|
if(lastReturned == next) next = next.previous();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
|
|||||||
@@ -54,6 +54,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +169,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;
|
||||||
@@ -554,348 +555,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
if (a.length > size) a[size] = null;
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disabled until a Proper Implementation can be thought out or it is decided that the interface is thrown out.
|
|
||||||
// private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
|
||||||
// int offset;
|
|
||||||
// int length;
|
|
||||||
//
|
|
||||||
// SubSet(int offset, int length) {
|
|
||||||
// this.offset = offset;
|
|
||||||
// this.length = length;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// int end() { return offset+length; }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean add(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index == -1) {
|
|
||||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
// if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
|
|
||||||
// data[end()] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean addAndMoveToFirst(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index == -1) {
|
|
||||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
// System.arraycopy(data, offset, data, offset+1, size-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// else if(index != 0) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean addAndMoveToLast(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index == -1) {
|
|
||||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
// System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
// data[end()] = o;
|
|
||||||
// size++;
|
|
||||||
// length++;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// else if(index != 0) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset+1, data, offset, index-offset);
|
|
||||||
// data[offset+length] = o;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean moveToFirst(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index > offset) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
// data[offset] = o;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean moveToLast(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1 && index < end()-1) {
|
|
||||||
// o = data[index];
|
|
||||||
// System.arraycopy(data, index+1, data, index, end()-index-1);
|
|
||||||
// data[end()-1] = o;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public boolean contains(KEY_TYPE e) {
|
|
||||||
// return findIndex(e) != -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// public boolean contains(Object e) {
|
|
||||||
// return findIndex(e) != -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE FIRST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// return data[offset];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE LAST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// return data[end()-1];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public boolean remove(KEY_TYPE o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1) {
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// public boolean remove(Object o) {
|
|
||||||
// int index = findIndex(o);
|
|
||||||
// if(index != -1) {
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE POLL_FIRST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// KEY_TYPE result = data[offset];
|
|
||||||
// System.arraycopy(data, offset+1, data, offset, size-offset);
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE POLL_LAST_KEY() {
|
|
||||||
// if(length == 0) throw new NoSuchElementException();
|
|
||||||
// KEY_TYPE result = data[offset+length];
|
|
||||||
// size--;
|
|
||||||
// length--;
|
|
||||||
// System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
//#if TYPE_OBJECT
|
|
||||||
// data[size] = EMPTY_KEY_VALUE;
|
|
||||||
//#endif
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
// return new SetIterator(offset);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
|
||||||
// int index = findIndex(fromElement);
|
|
||||||
// if(index != -1) return new SetIterator(index);
|
|
||||||
// throw new NoSuchElementException();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SubSet copy() { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
|
||||||
// int fromIndex = findIndex(fromElement);
|
|
||||||
// int toIndex = findIndex(toElement);
|
|
||||||
// if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
|
||||||
// int toIndex = findIndex(toElement);
|
|
||||||
// if(toIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(0, toIndex+1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
|
||||||
// int fromIndex = findIndex(fromElement);
|
|
||||||
// if(fromIndex == -1) throw new NoSuchElementException();
|
|
||||||
// return new SubSet(fromIndex, size - fromIndex);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int size() {
|
|
||||||
// return length;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
||||||
// if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
|
|
||||||
// System.arraycopy(data, offset, a, 0, size());
|
|
||||||
// return a;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// @Override
|
|
||||||
// @Deprecated
|
|
||||||
// public Object[] toArray() {
|
|
||||||
// Object[] obj = new Object[size()];
|
|
||||||
// for(int i = 0;i<size();i++)
|
|
||||||
// obj[i] = KEY_TO_OBJ(data[offset+i]);
|
|
||||||
// return obj;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// @Primitive
|
|
||||||
// public <E> E[] toArray(E[] a) {
|
|
||||||
// if(a == null) a = (E[])new Object[size()];
|
|
||||||
// else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
|
||||||
// for(int i = 0;i<size();i++)
|
|
||||||
// a[i] = (E)KEY_TO_OBJ(data[offset+i]);
|
|
||||||
// return a;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#if !TYPE_OBJECT
|
|
||||||
// protected int findIndex(KEY_TYPE o) {
|
|
||||||
// for(int i = length-1;i>=0;i--)
|
|
||||||
// if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//#endif
|
|
||||||
// protected int findIndex(Object o) {
|
|
||||||
// for(int i = length-1;i>=0;i--)
|
|
||||||
// if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
|
||||||
// int index;
|
|
||||||
// int lastReturned = -1;
|
|
||||||
//
|
|
||||||
// public SetIterator(int index) {
|
|
||||||
// this.index = index;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean hasNext() {
|
|
||||||
// return index < size();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE NEXT() {
|
|
||||||
// if(!hasNext()) throw new NoSuchElementException();
|
|
||||||
// lastReturned = index;
|
|
||||||
// return data[index++];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean hasPrevious() {
|
|
||||||
// return index > 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public KEY_TYPE PREVIOUS() {
|
|
||||||
// if(!hasPrevious()) throw new NoSuchElementException();
|
|
||||||
// lastReturned = index;
|
|
||||||
// return data[index--];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int nextIndex() {
|
|
||||||
// return index;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int previousIndex() {
|
|
||||||
// return index-1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void remove() {
|
|
||||||
// if(lastReturned == -1)
|
|
||||||
// throw new IllegalStateException();
|
|
||||||
// SubSet.this.remove(data[lastReturned]);
|
|
||||||
// if(lastReturned < index)
|
|
||||||
// index--;
|
|
||||||
// lastReturned = -1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// #if TYPE_OBJECT
|
|
||||||
// @Override
|
|
||||||
// public void set(Object e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void add(Object e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// #else
|
|
||||||
// @Override
|
|
||||||
// public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
||||||
//
|
|
||||||
// #endif
|
|
||||||
// @Override
|
|
||||||
// public int skip(int amount) {
|
|
||||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
|
||||||
// int steps = Math.min(amount, (size() - 1) - index);
|
|
||||||
// index += steps;
|
|
||||||
// return steps;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int back(int amount) {
|
|
||||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
|
||||||
// int steps = Math.min(amount, index);
|
|
||||||
// index -= steps;
|
|
||||||
// return steps;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
@@ -924,8 +584,8 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = index;
|
--index;
|
||||||
return data[index--];
|
return data[(lastReturned = index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -964,8 +624,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -974,6 +635,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-4
@@ -502,6 +502,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;
|
||||||
@@ -530,9 +554,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];
|
||||||
}
|
}
|
||||||
@@ -540,9 +563,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-12
@@ -123,7 +123,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]);
|
||||||
}
|
}
|
||||||
@@ -237,6 +237,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;
|
||||||
@@ -249,6 +250,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;
|
||||||
@@ -282,7 +284,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);
|
||||||
@@ -304,7 +306,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);
|
||||||
@@ -370,8 +372,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)) {
|
||||||
@@ -393,8 +394,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)) {
|
||||||
@@ -508,7 +508,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;
|
||||||
}
|
}
|
||||||
@@ -715,6 +715,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();
|
||||||
@@ -773,9 +797,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];
|
||||||
}
|
}
|
||||||
@@ -783,9 +806,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-12
@@ -110,7 +110,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]);
|
||||||
}
|
}
|
||||||
@@ -208,6 +208,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;
|
||||||
@@ -220,6 +221,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;
|
||||||
@@ -253,7 +255,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);
|
||||||
@@ -275,7 +277,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);
|
||||||
@@ -341,8 +343,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)) {
|
||||||
@@ -364,8 +365,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)) {
|
||||||
@@ -599,7 +599,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;
|
||||||
}
|
}
|
||||||
@@ -676,6 +676,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;
|
||||||
@@ -744,9 +768,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];
|
||||||
}
|
}
|
||||||
@@ -754,9 +777,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -373,10 +373,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;
|
||||||
@@ -385,7 +385,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;
|
||||||
}
|
}
|
||||||
@@ -589,7 +589,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
state = keys[nullIndex];
|
state = keys[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
|
|||||||
+5
-5
@@ -340,10 +340,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;
|
||||||
@@ -352,7 +352,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;
|
||||||
}
|
}
|
||||||
@@ -452,7 +452,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
state = keys[nullIndex];
|
state = keys[nullIndex];
|
||||||
empty = false;
|
empty = false;
|
||||||
}
|
}
|
||||||
for(int i = 0;i<size;i++) {
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
if(empty) {
|
if(empty) {
|
||||||
empty = false;
|
empty = false;
|
||||||
|
|||||||
+41
-27
@@ -949,15 +949,11 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMaxValue() { return super.getDefaultMinValue(); }
|
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMinValue() { return super.getDefaultMaxValue(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||||
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
||||||
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
||||||
return new DescendingSubSetBRACES(set, false, fromElement, fromInclusive, false, toElement, toInclusive);
|
return new DescendingSubSetBRACES(set, false, toElement, toInclusive, false, fromElement, fromInclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1034,21 +1030,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||||
|
|
||||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
@@ -1359,6 +1349,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
@@ -1368,6 +1359,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.previous();
|
||||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
@@ -1383,6 +1375,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.next();
|
next = next.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
@@ -1391,15 +1384,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.previous();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1407,6 +1401,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(previous == lastReturned) previous = previous.previous();
|
||||||
|
if(next == lastReturned) next = next.next();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
set.removeNode(lastReturned);
|
set.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1417,6 +1413,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
boolean unboundForwardFence;
|
boolean unboundForwardFence;
|
||||||
boolean unboundBackwardFence;
|
boolean unboundBackwardFence;
|
||||||
@@ -1426,6 +1423,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.next();
|
||||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
@@ -1441,6 +1439,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.previous();
|
next = next.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
@@ -1449,15 +1448,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.next();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1465,6 +1465,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(previous == lastReturned) previous = previous.next();
|
||||||
|
if(next == lastReturned) next = next.previous();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
set.removeNode(lastReturned);
|
set.removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1476,11 +1478,13 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
|
|
||||||
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1492,6 +1496,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.next();
|
next = next.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
@@ -1500,15 +1505,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.previous();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1516,6 +1522,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(lastReturned == previous) previous = previous.previous();
|
||||||
|
if(lastReturned == next) next = next.next();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
@@ -1526,11 +1534,13 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
Entry KEY_GENERIC_TYPE previous;
|
||||||
boolean forwards = false;
|
boolean forwards = false;
|
||||||
|
|
||||||
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
|
previous = first == null ? null : first.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1542,6 +1552,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = next;
|
||||||
|
previous = next;
|
||||||
KEY_TYPE result = next.key;
|
KEY_TYPE result = next.key;
|
||||||
next = next.previous();
|
next = next.previous();
|
||||||
forwards = false;
|
forwards = false;
|
||||||
@@ -1550,15 +1561,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return next != null;
|
return previous != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
if(!hasPrevious()) throw new NoSuchElementException();
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
lastReturned = next;
|
lastReturned = previous;
|
||||||
KEY_TYPE result = next.key;
|
next = previous;
|
||||||
next = next.next();
|
KEY_TYPE result = previous.key;
|
||||||
|
previous = previous.next();
|
||||||
forwards = true;
|
forwards = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1566,6 +1578,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
|
if(lastReturned == previous) previous = previous.next();
|
||||||
|
if(lastReturned == next) next = next.previous();
|
||||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||||
removeNode(lastReturned);
|
removeNode(lastReturned);
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
|
|||||||
@@ -348,9 +348,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
|
* @return input array.
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
stableSort(array, 0, array.length, comp);
|
stableSort(array, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,9 +388,11 @@ public class ARRAYS
|
|||||||
* Stable sort referres to Mergesort or Insertionsort
|
* Stable sort referres to Mergesort or Insertionsort
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] stableSort(KEY_TYPE[] array) {
|
||||||
stableSort(array, 0, array.length);
|
stableSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,9 +427,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
unstableSort(array, 0, array.length, comp);
|
unstableSort(array, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -461,9 +467,11 @@ public class ARRAYS
|
|||||||
* Unstable sort referres to QuickSort or SelectionSort
|
* Unstable sort referres to QuickSort or SelectionSort
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] unstableSort(KEY_TYPE[] array) {
|
||||||
unstableSort(array, 0, array.length);
|
unstableSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -496,9 +504,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
insertionSort(array, 0, array.length, comp);
|
insertionSort(array, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -535,9 +545,11 @@ public class ARRAYS
|
|||||||
* Sorts an array according to the natural ascending order using InsertionSort,
|
* Sorts an array according to the natural ascending order using InsertionSort,
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] insertionSort(KEY_TYPE[] array) {
|
||||||
insertionSort(array, 0, array.length);
|
insertionSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -573,9 +585,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
selectionSort(array, 0, array.length, comp);
|
selectionSort(array, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -617,9 +631,11 @@ public class ARRAYS
|
|||||||
* Sorts an array according to the natural ascending order using Selection Sort,
|
* Sorts an array according to the natural ascending order using Selection Sort,
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] selectionSort(KEY_TYPE[] array) {
|
||||||
selectionSort(array, 0, array.length);
|
selectionSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -661,9 +677,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
mergeSort(array, null, 0, array.length, comp);
|
mergeSort(array, null, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -713,9 +731,11 @@ public class ARRAYS
|
|||||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] mergeSort(KEY_TYPE[] array) {
|
||||||
mergeSort(array, null, 0, array.length);
|
mergeSort(array, null, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -922,9 +942,11 @@ public class ARRAYS
|
|||||||
* @author Speiger
|
* @author Speiger
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] memFreeMergeSort(KEY_TYPE[] array) {
|
||||||
memFreeMergeSort(array, 0, array.length);
|
memFreeMergeSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1099,9 +1121,11 @@ public class ARRAYS
|
|||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @param comp the Comparator that decides the sorting order
|
* @param comp the Comparator that decides the sorting order
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||||
quickSort(array, 0, array.length, comp);
|
quickSort(array, 0, array.length, comp);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1157,9 +1181,11 @@ public class ARRAYS
|
|||||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||||
* @param array the array that needs to be sorted
|
* @param array the array that needs to be sorted
|
||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
|
* @return input array
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array) {
|
public static GENERIC_KEY_BRACES KEY_TYPE[] quickSort(KEY_TYPE[] array) {
|
||||||
quickSort(array, 0, array.length);
|
quickSort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+33
-1
@@ -7,12 +7,13 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
import java.util.concurrent.locks.LockSupport;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#else
|
#else
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
@@ -112,6 +113,16 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.
|
||||||
|
* @param values that should be wrapped
|
||||||
|
* @Type(T)
|
||||||
|
* @return a AsyncBuilder with the values wrapped
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ASYNC_BUILDER KEY_GENERIC_TYPE of(KEY_TYPE...values) {
|
||||||
|
return new ASYNC_BUILDERBRACES(ARRAY_LIST.wrap(values));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the elements to something else
|
* Maps the elements to something else
|
||||||
* @param mapper the mapping function
|
* @param mapper the mapping function
|
||||||
@@ -162,6 +173,16 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeats the elements inside of the Iterable
|
||||||
|
* @param repeats the amount of times the elements should be repeated
|
||||||
|
* @return self with a repeater applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE repeat(int repeats) {
|
||||||
|
iterable = ITERABLES.repeat(iterable, repeats);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Limits how many elements are inside of the Iterable
|
* Limits how many elements are inside of the Iterable
|
||||||
* @param limit how many elements should max be iterated through
|
* @param limit how many elements should max be iterated through
|
||||||
@@ -172,6 +193,17 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the elements inside of the Iterable.
|
||||||
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it, and this will affect the pausing feature.
|
||||||
|
* @param sorter that sorts the elements.
|
||||||
|
* @return self with a sorter applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
iterable = ITERABLES.sorted(iterable, sorter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to preview elements before they are processed
|
* Allows to preview elements before they are processed
|
||||||
* @param action the action that should be applied
|
* @param action the action that should be applied
|
||||||
|
|||||||
+24
-7
@@ -186,7 +186,10 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
|
public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } }
|
public boolean equals(Object obj) {
|
||||||
|
if(obj == this) return true;
|
||||||
|
synchronized(mutex) { return c.equals(obj); }
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() { synchronized(mutex) { return c.toString(); } }
|
public String toString() { synchronized(mutex) { return c.toString(); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -308,7 +311,7 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() { return c.hashCode(); }
|
public int hashCode() { return c.hashCode(); }
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) { return c.equals(obj); }
|
public boolean equals(Object obj) { return obj == this || c.equals(obj); }
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return c.toString(); }
|
public String toString() { return c.toString(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -350,7 +353,7 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public boolean contains(KEY_TYPE o) { return false; }
|
public boolean contains(KEY_TYPE o) { return false; }
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return c.isEmpty(); }
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
||||||
#else
|
#else
|
||||||
@@ -362,7 +365,7 @@ public class COLLECTIONS
|
|||||||
public boolean containsAny(Collection<?> c) { return false; }
|
public boolean containsAny(Collection<?> c) { return false; }
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean containsAll(Collection<?> c) { return false; }
|
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() { return 0; }
|
public int hashCode() { return 0; }
|
||||||
|
|
||||||
@@ -401,14 +404,28 @@ public class COLLECTIONS
|
|||||||
public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; }
|
public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public <T> T[] toArray(T[] a) { return a; }
|
public <T> T[] toArray(T[] a) {
|
||||||
|
if(a != null && a.length > 0)
|
||||||
|
a[0] = null;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; }
|
public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return a; }
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
|
if(a != null && a.length > 0)
|
||||||
|
a[0] = EMPTY_KEY_VALUE;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public <E> E[] toArray(E[] a) { return a; }
|
public <E> E[] toArray(E[] a) {
|
||||||
|
if(a != null && a.length > 0)
|
||||||
|
a[0] = EMPTY_KEY_VALUE;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); }
|
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); }
|
||||||
|
|||||||
+164
-4
@@ -3,6 +3,8 @@ package speiger.src.collections.PACKAGE.utils;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_BOOLEAN
|
#if TYPE_BOOLEAN
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -12,14 +14,18 @@ import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
|||||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.utils.ISizeProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper class for Iterables
|
* A Helper class for Iterables
|
||||||
@@ -142,6 +148,28 @@ public class ITERABLES
|
|||||||
return new DistinctIterableBRACES(wrap(iterable));
|
return new DistinctIterableBRACES(wrap(iterable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that repeats the Iterable a specific amount of times
|
||||||
|
* @param iterable that should be repeated
|
||||||
|
* @param repeats the amount of times the iterable should be repeated
|
||||||
|
* @Type(T)
|
||||||
|
* @return a repeating iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(ITERABLE KEY_GENERIC_TYPE iterable, int repeats) {
|
||||||
|
return new RepeatingIterableBRACES(iterable, repeats);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that repeats the Iterable a specific amount of times from a Java Iterable
|
||||||
|
* @param iterable that should be repeated
|
||||||
|
* @param repeats the amount of times the iterable should be repeated
|
||||||
|
* @Type(T)
|
||||||
|
* @return a repeating iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE repeat(Iterable<? extends CLASS_TYPE> iterable, int repeats) {
|
||||||
|
return new RepeatingIterableBRACES(wrap(iterable), repeats);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function that hard limits the Iterable to a specific size
|
* A Helper function that hard limits the Iterable to a specific size
|
||||||
* @param iterable that should be limited
|
* @param iterable that should be limited
|
||||||
@@ -164,6 +192,30 @@ public class ITERABLES
|
|||||||
return new LimitedIterableBRACES(wrap(iterable), limit);
|
return new LimitedIterableBRACES(wrap(iterable), limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* A Helper function that allows to preview the result of a Iterable.
|
||||||
* @param iterable that should be peeked at
|
* @param iterable that should be peeked at
|
||||||
@@ -196,7 +248,7 @@ public class ITERABLES
|
|||||||
return new WrappedIterableBRACES(iterable);
|
return new WrappedIterableBRACES(iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
{
|
{
|
||||||
Iterable<? extends CLASS_TYPE> iterable;
|
Iterable<? extends CLASS_TYPE> iterable;
|
||||||
|
|
||||||
@@ -208,6 +260,12 @@ public class ITERABLES
|
|||||||
return ITERATORS.wrap(iterable.iterator());
|
return ITERATORS.wrap(iterable.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER action) {
|
public void forEach(CONSUMER action) {
|
||||||
@@ -222,7 +280,7 @@ public class ITERABLES
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
|
||||||
{
|
{
|
||||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||||
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper;
|
TO_OBJECT_FUNCTION KSS_GENERIC_TYPE<E, T> mapper;
|
||||||
@@ -236,6 +294,12 @@ public class ITERABLES
|
|||||||
return ITERATORS.map(iterable.iterator(), mapper);
|
return ITERATORS.map(iterable.iterator(), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(this);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(Consumer<? super T> action) {
|
public void forEach(Consumer<? super T> action) {
|
||||||
Objects.requireNonNull(action);
|
Objects.requireNonNull(action);
|
||||||
@@ -291,6 +355,48 @@ public class ITERABLES
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
iterable.forEach(action.andThen(list::add));
|
||||||
|
for(int i = 0;i<repeats;i++)
|
||||||
|
list.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
iterable.forEach(T -> {action.accept(T); list.add(T);});
|
||||||
|
for(int i = 0;i<repeats;i++)
|
||||||
|
list.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
@@ -320,7 +426,7 @@ public class ITERABLES
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
{
|
{
|
||||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
long limit;
|
long limit;
|
||||||
@@ -335,6 +441,12 @@ public class ITERABLES
|
|||||||
return ITERATORS.limit(iterable.iterator(), limit);
|
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
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER action) {
|
public void forEach(CONSUMER action) {
|
||||||
@@ -359,6 +471,48 @@ public class ITERABLES
|
|||||||
#endif
|
#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);
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
iterable.forEach(list::add);
|
||||||
|
list.unstableSort(sorter);
|
||||||
|
list.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
iterable.forEach(list::add);
|
||||||
|
list.unstableSort(sorter);
|
||||||
|
list.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
@@ -397,7 +551,7 @@ public class ITERABLES
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE, ISizeProvider
|
||||||
{
|
{
|
||||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
CONSUMER KEY_GENERIC_TYPE action;
|
CONSUMER KEY_GENERIC_TYPE action;
|
||||||
@@ -412,6 +566,12 @@ public class ITERABLES
|
|||||||
return ITERATORS.peek(iterable.iterator(), action);
|
return ITERATORS.peek(iterable.iterator(), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
ISizeProvider prov = ISizeProvider.of(iterable);
|
||||||
|
return prov == null ? -1 : prov.size();
|
||||||
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER action) {
|
public void forEach(CONSUMER action) {
|
||||||
|
|||||||
+121
-11
@@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.utils;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.function.CONSUMER;
|
import java.util.function.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
@@ -32,7 +34,7 @@ public class ITERATORS
|
|||||||
/**
|
/**
|
||||||
* Empty Iterator Reference
|
* Empty Iterator Reference
|
||||||
*/
|
*/
|
||||||
public static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
private static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||||
@@ -213,6 +215,28 @@ public class ITERATORS
|
|||||||
return new DistinctIteratorBRACES(wrap(iterator));
|
return new DistinctIteratorBRACES(wrap(iterator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that repeats the Iterator a specific amount of times
|
||||||
|
* @param iterator that should be repeated
|
||||||
|
* @param repeats the amount of times the iterator should be repeated
|
||||||
|
* @Type(T)
|
||||||
|
* @return a repeating iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE repeat(ITERATOR KEY_GENERIC_TYPE iterator, int repeats) {
|
||||||
|
return new RepeatingIteratorBRACES(iterator, repeats);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that repeats the Iterator a specific amount of times from a Java Iterator
|
||||||
|
* @param iterator that should be repeated
|
||||||
|
* @param repeats the amount of times the iterator should be repeated
|
||||||
|
* @Type(T)
|
||||||
|
* @return a repeating iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE repeat(Iterator<? extends CLASS_TYPE> iterator, int repeats) {
|
||||||
|
return new RepeatingIteratorBRACES(wrap(iterator), repeats);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function that hard limits the Iterator to a specific size
|
* A Helper function that hard limits the Iterator to a specific size
|
||||||
* @param iterator that should be limited
|
* @param iterator that should be limited
|
||||||
@@ -235,6 +259,30 @@ public class ITERATORS
|
|||||||
return new LimitedIteratorBRACES(wrap(iterator), limit);
|
return new LimitedIteratorBRACES(wrap(iterator), limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that sorts the Iterator beforehand.
|
||||||
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||||
|
* @param iterator that should be sorted.
|
||||||
|
* @param sorter the sorter of the iterator. Can be null.
|
||||||
|
* @Type(T)
|
||||||
|
* @return a new sorted iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return new SortedIteratorBRACES(iterator, sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that sorts the Iterator beforehand from a Java Iterator.
|
||||||
|
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||||
|
* @param iterator that should be sorted.
|
||||||
|
* @param sorter the sorter of the iterator. Can be null.
|
||||||
|
* @Type(T)
|
||||||
|
* @return a new sorted iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(Iterator<? extends CLASS_TYPE> iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return new SortedIteratorBRACES(wrap(iterator), sorter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function that allows to preview the result of a Iterator.
|
* A Helper function that allows to preview the result of a Iterator.
|
||||||
* @param iterator that should be peeked at
|
* @param iterator that should be peeked at
|
||||||
@@ -273,7 +321,7 @@ public class ITERATORS
|
|||||||
* @ArrayType(T)
|
* @ArrayType(T)
|
||||||
* @return a Iterator that is wrapping a array.
|
* @return a Iterator that is wrapping a array.
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||||
return wrap(a, 0, a.length);
|
return wrap(a, 0, a.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +757,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
return EMPTY_KEY_VALUE;
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -719,7 +767,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
return EMPTY_KEY_VALUE;
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -729,7 +777,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int previousIndex() {
|
public int previousIndex() {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -761,6 +809,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return a[from++];
|
return a[from++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -828,7 +877,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
T result = last.next();
|
T result = last.next();
|
||||||
foundNext = false;
|
foundNext = false;
|
||||||
return result;
|
return result;
|
||||||
@@ -864,13 +913,74 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
T result = last.next();
|
T result = last.next();
|
||||||
foundNext = false;
|
foundNext = false;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class RepeatingIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
final int repeats;
|
||||||
|
int index = 0;
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
|
||||||
|
public RepeatingIterator(ITERATOR KEY_GENERIC_TYPE iter, int repeat) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.repeats = repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
if(iter.hasNext()) return true;
|
||||||
|
if(index < repeats) {
|
||||||
|
index++;
|
||||||
|
iter = list.iterator();
|
||||||
|
return iter.hasNext();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
KEY_TYPE value = iter.NEXT();
|
||||||
|
if(index == 0) list.add(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SortedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
|
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||||
|
LIST KEY_GENERIC_TYPE sortedElements = null;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
public SortedIterator(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
this.sorter = sorter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
if(sortedElements == null) {
|
||||||
|
boolean hasNext = iterator.hasNext();
|
||||||
|
sortedElements = hasNext ? pour(iterator) : LISTS.empty();
|
||||||
|
if(hasNext) sortedElements.unstableSort(sorter);
|
||||||
|
}
|
||||||
|
return index < sortedElements.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return sortedElements.GET_KEY(index++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class DistinctIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
private static class DistinctIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
@@ -916,7 +1026,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
foundNext = false;
|
foundNext = false;
|
||||||
return lastFound;
|
return lastFound;
|
||||||
}
|
}
|
||||||
@@ -953,7 +1063,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
foundNext = false;
|
foundNext = false;
|
||||||
return lastFound;
|
return lastFound;
|
||||||
}
|
}
|
||||||
@@ -976,7 +1086,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
limit--;
|
limit--;
|
||||||
return iterator.NEXT();
|
return iterator.NEXT();
|
||||||
}
|
}
|
||||||
@@ -999,7 +1109,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
KEY_TYPE result = iterator.NEXT();
|
KEY_TYPE result = iterator.NEXT();
|
||||||
action.accept(result);
|
action.accept(result);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.RandomAccess;
|
import java.util.RandomAccess;
|
||||||
@@ -27,7 +28,7 @@ public class LISTS
|
|||||||
/**
|
/**
|
||||||
* Empty List reference
|
* Empty List reference
|
||||||
*/
|
*/
|
||||||
public static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES();
|
private static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Immutable EmptyList instance that is automatically casted.
|
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||||
@@ -356,7 +357,7 @@ public class LISTS
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { addElements(from, a, offset, length); } }
|
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { l.addElements(from, a, offset, length); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { return l.getElements(from, a, offset, length); } }
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { return l.getElements(from, a, offset, length); } }
|
||||||
@@ -601,6 +602,16 @@ public class LISTS
|
|||||||
return ITERATORS.empty();
|
return ITERATORS.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return 1; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o == this) return true;
|
||||||
|
if(!(o instanceof List)) return false;
|
||||||
|
return ((List<?>)o).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); }
|
public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Set;
|
||||||
#if TYPE_BOOLEAN
|
#if TYPE_BOOLEAN
|
||||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||||
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
||||||
@@ -34,7 +36,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
|
||||||
@@ -216,10 +218,10 @@ public class SETS
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -241,6 +243,13 @@ public class SETS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
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; }
|
||||||
}
|
}
|
||||||
@@ -258,25 +267,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(); }
|
||||||
|
|
||||||
@@ -291,7 +313,7 @@ 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 SETS.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)); }
|
||||||
@@ -454,27 +476,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); } }
|
||||||
|
|
||||||
|
|||||||
+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; }
|
||||||
}
|
}
|
||||||
|
|||||||
+157
-34
@@ -19,8 +19,11 @@ import speiger.src.collections.objects.collections.ObjectIterable;
|
|||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
import speiger.src.collections.objects.sets.ObjectSet;
|
||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||||
import speiger.src.collections.objects.utils.ObjectSets;
|
import speiger.src.collections.objects.utils.ObjectSets;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
@@ -34,6 +37,8 @@ import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
@@ -42,6 +47,7 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
|||||||
#if !SAME_TYPE
|
#if !SAME_TYPE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_COLLECTIONS;
|
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_COLLECTIONS;
|
||||||
#if !SAME_TYPE && !VALUE_OBJECT
|
#if !SAME_TYPE && !VALUE_OBJECT
|
||||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_SETS;
|
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_SETS;
|
||||||
@@ -57,7 +63,21 @@ public class MAPS
|
|||||||
/**
|
/**
|
||||||
* Empty Map Variable
|
* Empty Map Variable
|
||||||
*/
|
*/
|
||||||
public static final MAP NO_KV_GENERIC_TYPE EMPTY = new EmptyMapKV_BRACES();
|
private static final MAP NO_KV_GENERIC_TYPE EMPTY = new EmptyMapKV_BRACES();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty Map getter function that autocasts to the desired Key and Value
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
* @return empty map of desired type
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE empty() {
|
||||||
|
#if TYPE_OBJECT || VALUE_OBJECT
|
||||||
|
return (MAP KEY_VALUE_GENERIC_TYPE)EMPTY;
|
||||||
|
#else
|
||||||
|
return EMPTY;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
@@ -104,19 +124,6 @@ public class MAPS
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
/**
|
|
||||||
* Empty Map getter function that autocasts to the desired Key and Value
|
|
||||||
* @Type(T)
|
|
||||||
* @ValueType(V)
|
|
||||||
* @return empty map of desired type
|
|
||||||
*/
|
|
||||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE empty() {
|
|
||||||
#if TYPE_OBJECT || VALUE_OBJECT
|
|
||||||
return (MAP KEY_VALUE_GENERIC_TYPE)EMPTY;
|
|
||||||
#else
|
|
||||||
return EMPTY;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that creates a Helper wrapper to synchronize access into the map.
|
* Helper function that creates a Helper wrapper to synchronize access into the map.
|
||||||
@@ -253,7 +260,7 @@ public class MAPS
|
|||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
* @return a Unmodifyable Entry
|
* @return a Unmodifyable Entry
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { return entry instanceof UnmodifyableEntry ? entry : new UnmodifyableEntryKV_BRACES(entry); }
|
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { return entry instanceof UnmodifyableEntry ? entry : (entry == null ? null : new UnmodifyableEntryKV_BRACES(entry)); }
|
||||||
/**
|
/**
|
||||||
* A Helper function that creates a Unmodifyable Entry
|
* A Helper function that creates a Unmodifyable Entry
|
||||||
* @param entry the Entry that should be made unmodifiable
|
* @param entry the Entry that should be made unmodifiable
|
||||||
@@ -261,7 +268,7 @@ public class MAPS
|
|||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
* @return a Unmodifyable Entry
|
* @return a Unmodifyable Entry
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) { return entry instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)entry : new UnmodifyableEntryKV_BRACES(entry); }
|
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) { return entry instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)entry : (entry == null ? null : new UnmodifyableEntryKV_BRACES(entry)); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Singleton map from the provided values.
|
* Creates a Singleton map from the provided values.
|
||||||
@@ -315,6 +322,18 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
|
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
|
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
|
||||||
@Override
|
@Override
|
||||||
@@ -363,8 +382,20 @@ public class MAPS
|
|||||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return getDefaultReturnValue(); }
|
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return getDefaultReturnValue(); }
|
||||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EMPTY_VALUE; }
|
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return defaultValue; }
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() { return SETS.empty(); }
|
public SET KEY_GENERIC_TYPE keySet() { return SETS.empty(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -408,10 +439,12 @@ public class MAPS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.synchronize(map.descendingMap()); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.unmodifiable(map.descendingMap()); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { return SETS.unmodifiable(map.navigableKeySet()); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { return SETS.unmodifiable(map.navigableKeySet()); }
|
||||||
@Override
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() { return SETS.unmodifiable(map.keySet()); }
|
||||||
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { return SETS.unmodifiable(map.descendingKeySet()); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { return SETS.unmodifiable(map.descendingKeySet()); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); }
|
||||||
@@ -460,7 +493,7 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.ceilingEntry(key)); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.ceilingEntry(key)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -491,17 +524,28 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||||
@Override
|
@Override
|
||||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
|
if(keys == null) keys = SETS.unmodifiable(map.keySet());
|
||||||
|
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
|
if(entrySet == null) entrySet = new UnmodifyableOrderedEntrySetKV_BRACES(map.ENTRY_SET());
|
||||||
|
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -526,19 +570,21 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||||
@Override
|
@Override
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE keySet() { return SETS.unmodifiable(map.keySet()); }
|
||||||
|
@Override
|
||||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -575,13 +621,34 @@ public class MAPS
|
|||||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
public VALUE_TYPE GET_VALUE(KEY_TYPE key) {
|
||||||
|
VALUE_TYPE type = map.GET_VALUE(key);
|
||||||
|
return VALUE_EQUALS(type, map.getDefaultReturnValue()) && !map.containsKey(key) ? getDefaultReturnValue() : type;
|
||||||
|
}
|
||||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||||
|
@Override
|
||||||
|
public void clear() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public SET KEY_GENERIC_TYPE keySet() {
|
||||||
@@ -602,6 +669,45 @@ public class MAPS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Unmodifyable Ordered Set implementation for the Unmodifyable Ordered Map implementation
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public static class UnmodifyableOrderedEntrySet KEY_VALUE_GENERIC_TYPE extends UnmodifyableEntrySet KEY_VALUE_GENERIC_TYPE implements ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||||
|
{
|
||||||
|
ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> set;
|
||||||
|
|
||||||
|
UnmodifyableOrderedEntrySet(ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> c) {
|
||||||
|
super(c);
|
||||||
|
set = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> copy() { return set.copy(); }
|
||||||
|
@Override
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ObjectIterators.unmodifiable(set.iterator()); }
|
||||||
|
@Override
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { return ObjectIterators.unmodifiable(set.iterator(fromElement)); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() { return set.first(); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() { return set.last(); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Unmodifyable Set implementation for the Unmodifyable Map implementation
|
* The Unmodifyable Set implementation for the Unmodifyable Map implementation
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -660,9 +766,11 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { synchronized(mutex) { return SETS.synchronize(map.descendingKeySet(), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { synchronized(mutex) { return SETS.synchronize(map.descendingKeySet(), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() { synchronized(mutex) { return SETS.synchronize(map.keySet(), mutex); } }
|
||||||
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -696,8 +804,8 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||||
@@ -794,7 +902,18 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||||
@Override
|
@Override
|
||||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||||
|
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||||
|
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
|
if(entrySet == null) entrySet = ObjectSets.synchronize(map.ENTRY_SET(), mutex);
|
||||||
|
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -824,6 +943,8 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE keySet() { synchronized(mutex) { return SETS.synchronize(map.keySet(), mutex); } }
|
||||||
|
@Override
|
||||||
public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } }
|
public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_FIRST_ENTRY_KEY(); } }
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_FIRST_ENTRY_KEY(); } }
|
||||||
@@ -836,7 +957,7 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -940,6 +1061,8 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
||||||
@Override
|
@Override
|
||||||
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
|
||||||
|
@Override
|
||||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
|
||||||
@Override
|
@Override
|
||||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { map.BULK_MERGE(m, mappingFunction); } }
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { map.BULK_MERGE(m, mappingFunction); } }
|
||||||
@@ -950,9 +1073,9 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) { synchronized(mutex) { map.forEach(action); } }
|
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) { synchronized(mutex) { map.forEach(action); } }
|
||||||
@Override
|
@Override
|
||||||
public int size() { synchronized(mutex) { return super.size(); } }
|
public int size() { synchronized(mutex) { return map.size(); } }
|
||||||
@Override
|
@Override
|
||||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE keySet() {
|
public SET KEY_GENERIC_TYPE keySet() {
|
||||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||||
|
|||||||
+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder;
|
||||||
|
|
||||||
|
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.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
import com.google.common.collect.testing.testers.SortedSetNavigationTester;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.impl.SUB_SORTED_SET_CLASS_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESortedSetIterationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESortedSetNaviationTester;
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||||
|
public static GENERIC_KEY_BRACES SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return (SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE) new SORTED_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(SortedSetNavigationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESortedSetIterationTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPESortedSetNaviationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite createTestSuite() {
|
||||||
|
if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
|
||||||
|
List<Feature<?>> features = Helpers.copyToList(getFeatures());
|
||||||
|
#ignore
|
||||||
|
features.add(CollectionFeature.KNOWN_ORDER);
|
||||||
|
#endignore
|
||||||
|
withFeatures(features);
|
||||||
|
}
|
||||||
|
return super.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(
|
||||||
|
FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
if (!parentBuilder.getFeatures().contains(CollectionFeature.SUBSET_VIEW)) {
|
||||||
|
#endignore
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND));
|
||||||
|
derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE));
|
||||||
|
}
|
||||||
|
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TestSuite createSubsetSuite(
|
||||||
|
FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder,
|
||||||
|
Bound from, Bound to) {
|
||||||
|
TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||||
|
|
||||||
|
List<Feature<?>> features = new ArrayList<>(parentBuilder.getFeatures());
|
||||||
|
#ignore
|
||||||
|
features.remove(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||||
|
features.add(CollectionFeature.SUBSET_VIEW);
|
||||||
|
features.remove(SpecialFeature.COPYING);
|
||||||
|
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
return newBuilderUsing(delegate, to, from).named(parentBuilder.getName() + " subSet " + from + "-" + to)
|
||||||
|
.withFeatures(features).suppressing(parentBuilder.getSuppressedTests())
|
||||||
|
.withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE newBuilderUsing(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
return using(new SUB_SORTED_SET_CLASS_GENERATORBRACES(delegate, to, from));
|
||||||
|
}
|
||||||
|
}
|
||||||
+304
@@ -0,0 +1,304 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder.maps;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.MapTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
import com.google.common.collect.testing.features.MapFeature;
|
||||||
|
import com.google.common.collect.testing.testers.CollectionIteratorTester;
|
||||||
|
#if VALUE_BOOLEAN
|
||||||
|
import com.google.common.collect.testing.testers.CollectionRemoveTester;
|
||||||
|
import com.google.common.collect.testing.testers.CollectionRetainAllTester;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.builder.VALUE_COLLECTION_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.generators.VALUE_TEST_COLLECTION_GENERATOR;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||||
|
#if TYPE_CHAR || TYPE_FLOAT || TYPE_DOUBLE
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester;
|
||||||
|
#if !SAME_TYPE && !VALUE_OBJECT
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester;
|
||||||
|
#endif
|
||||||
|
#else if TYPE_OBJECT && !VALUE_OBJECT
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester;
|
||||||
|
#endif
|
||||||
|
#if VALUE_PRIMITIVES
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapAddToTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSubFromTester;
|
||||||
|
#endif
|
||||||
|
#if VALUE_BOOLEAN
|
||||||
|
#if !TYPE_CHAR && !TYPE_FLOAT && !TYPE_DOUBLE && !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionRemoveAllTester;
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionRetainAllTester;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapEntrySetTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapEqualsTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapForEachTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetOrDefaultTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapHashCodeTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapIsEmptyTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeBulkTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllArrayTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveOrDefaultTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceAllTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceEntryTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester;
|
||||||
|
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
|
||||||
|
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||||
|
import speiger.src.testers.objects.tests.collection.ObjectCollectionIteratorTester;
|
||||||
|
import speiger.src.testers.objects.tests.collection.ObjectCollectionRemoveAllTester;
|
||||||
|
import speiger.src.testers.objects.tests.collection.ObjectCollectionRetainAllTester;
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
import speiger.src.testers.utils.TestUtils;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||||
|
boolean shouldBlockKeys;
|
||||||
|
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) {
|
||||||
|
return (MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE shouldBlockKeys(boolean value) {
|
||||||
|
shouldBlockKeys = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = new ArrayList<>();
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapEntrySetTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapEqualsTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapForEachTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetOrDefaultTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapHashCodeTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapIsEmptyTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeBulkTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutTester.class);
|
||||||
|
#if VALUE_PRIMITIVES
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapAddToTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSubFromTester.class);
|
||||||
|
#endif
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllArrayTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveOrDefaultTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceAllTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceEntryTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = new ArrayList<>();
|
||||||
|
derivedSuites.add(createDerivedEntrySetSuite(
|
||||||
|
DERIVED_MAP_GENERATORS.entrySetGenerator(parentBuilder.getSubjectGenerator()))
|
||||||
|
.withFeatures(computeEntrySetFeatures(parentBuilder.getFeatures()))
|
||||||
|
.named(parentBuilder.getName() + " entrySet")
|
||||||
|
.suppressing(getEntrySetSuppressing(parentBuilder.getSuppressedTests())).suppressing(getSuppressing(1))
|
||||||
|
.withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown())
|
||||||
|
.createTestSuite());
|
||||||
|
|
||||||
|
derivedSuites.add(createDerivedKeySetSuite(
|
||||||
|
DERIVED_MAP_GENERATORS.keySetGenerator(parentBuilder.getSubjectGenerator()))
|
||||||
|
.withFeatures(computeKeySetFeatures(parentBuilder.getFeatures()))
|
||||||
|
.named(parentBuilder.getName() + " keys").suppressing(parentBuilder.getSuppressedTests()).suppressing(getSuppressing(0))
|
||||||
|
.withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown())
|
||||||
|
.createTestSuite());
|
||||||
|
#if !TYPE_CHAR && !TYPE_OBJECT && !TYPE_FLOAT && !TYPE_DOUBLE || !VALUE_BOOLEAN
|
||||||
|
derivedSuites.add(createDerivedValueCollectionSuite(
|
||||||
|
new DERIVED_MAP_GENERATORS.MapValueCollectionGeneratorKV_BRACES(parentBuilder.getSubjectGenerator()))
|
||||||
|
.named(parentBuilder.getName() + " values")
|
||||||
|
.withFeatures(computeValuesCollectionFeatures(parentBuilder.getFeatures()))
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).suppressing(getSuppressing(2)).withSetUp(parentBuilder.getSetUp())
|
||||||
|
.withTearDown(parentBuilder.getTearDown()).createTestSuite());
|
||||||
|
#endif
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectSetTestSuiteBuilder<MAP.Entry KEY_VALUE_GENERIC_TYPE> createDerivedEntrySetSuite(TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySetGenerator) {
|
||||||
|
return ObjectSetTestSuiteBuilder.using(entrySetGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return SET_TEST_BUILDER.using(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected VALUE_COLLECTION_TEST_BUILDER VALUE_GENERIC_TYPE createDerivedValueCollectionSuite(VALUE_TEST_COLLECTION_GENERATOR VALUE_GENERIC_TYPE generator) {
|
||||||
|
return VALUE_COLLECTION_TEST_BUILDER.using(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method[] getSuppressing(int type) {
|
||||||
|
#if TYPE_CHAR || TYPE_OBJECT || TYPE_FLOAT || TYPE_DOUBLE
|
||||||
|
if(shouldBlockKeys) {
|
||||||
|
switch(type) {
|
||||||
|
case 0: return TestUtils.getSurpession(FILE_KEY_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
case 1: return TestUtils.getSurpession(ObjectCollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
case 2: {
|
||||||
|
List<Method> result = new ArrayList<>();
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
#if VALUE_BOOLEAN
|
||||||
|
TestUtils.getSurpession(result, CollectionRemoveTester.class, "testRemove_present");
|
||||||
|
TestUtils.getSurpession(result, CollectionRetainAllTester.class);
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection");
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements");
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRetainAllTester.class);
|
||||||
|
#endif
|
||||||
|
return result.toArray(new Method[result.size()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Method[0];
|
||||||
|
#else if VALUE_BOOLEAN
|
||||||
|
if(type == 2) {
|
||||||
|
List<Method> result = new ArrayList<>();
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
#if VALUE_BOOLEAN
|
||||||
|
TestUtils.getSurpession(result, CollectionRemoveTester.class, "testRemove_present");
|
||||||
|
TestUtils.getSurpession(result, CollectionRetainAllTester.class);
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection");
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements");
|
||||||
|
TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRetainAllTester.class);
|
||||||
|
#endif
|
||||||
|
return result.toArray(new Method[result.size()]);
|
||||||
|
}
|
||||||
|
return new Method[0];
|
||||||
|
#else
|
||||||
|
return new Method[0];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> mapFeatures) {
|
||||||
|
Set<Feature<?>> entrySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||||
|
#ignore
|
||||||
|
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) {
|
||||||
|
entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||||
|
}
|
||||||
|
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||||
|
entrySetFeatures.add(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entrySetFeatures.remove(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||||
|
entrySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entrySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||||
|
}
|
||||||
|
entrySetFeatures.add(SpecialFeature.MAP_ENTRY);
|
||||||
|
#endignore
|
||||||
|
return entrySetFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<Feature<?>> computeKeySetFeatures(Set<Feature<?>> mapFeatures) {
|
||||||
|
Set<Feature<?>> keySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||||
|
#ignore
|
||||||
|
keySetFeatures.add(CollectionFeature.SUBSET_VIEW);
|
||||||
|
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
|
||||||
|
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||||
|
} else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
|
||||||
|
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||||
|
}
|
||||||
|
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||||
|
keySetFeatures.add(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keySetFeatures.remove(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||||
|
keySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
keySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||||
|
}
|
||||||
|
#endignore
|
||||||
|
return keySetFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_CHAR && !TYPE_OBJECT && !TYPE_FLOAT && !TYPE_DOUBLE || !VALUE_BOOLEAN
|
||||||
|
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
|
||||||
|
Set<Feature<?>> valuesCollectionFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||||
|
#ignore
|
||||||
|
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
|
||||||
|
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||||
|
}
|
||||||
|
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
|
||||||
|
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||||
|
}
|
||||||
|
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||||
|
valuesCollectionFeatures.add(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
valuesCollectionFeatures.remove(SpecialFeature.COPYING);
|
||||||
|
}
|
||||||
|
#endignore
|
||||||
|
return valuesCollectionFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
private static Set<Method> getEntrySetSuppressing(Set<Method> suppressing) {
|
||||||
|
TestUtils.getSurpession(suppressing, CollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection");
|
||||||
|
TestUtils.getSurpession(suppressing, ObjectCollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection");
|
||||||
|
TestUtils.getSurpession(suppressing, ObjectCollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements");
|
||||||
|
TestUtils.getSurpession(suppressing, ObjectCollectionRetainAllTester.class, "testRetainAllExtra_disjointPreviouslyNonEmpty", "testRetainAllExtra_containsDuplicatesSizeSeveral", "testRetainAllExtra_subset", "testRetainAllExtra_partialOverlap");
|
||||||
|
#if TYPE_DOUBLE || TYPE_FLOAT
|
||||||
|
TestUtils.getSurpession(suppressing, CollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
TestUtils.getSurpession(suppressing, ObjectCollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
|
||||||
|
#endif
|
||||||
|
return suppressing;
|
||||||
|
}
|
||||||
|
}
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder.maps;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.features.Feature;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.testers.PACKAGE.builder.NAVIGABLE_SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPENavigableMapNavigationTester;
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) {
|
||||||
|
return (NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE)new NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = super.getTesters();
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPENavigableMapNavigationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||||
|
#ignore
|
||||||
|
if (!parentBuilder.getFeatures().contains(SpecialFeature.DESCENDING)) {
|
||||||
|
derivedSuites.add(createDescendingSuite(parentBuilder));
|
||||||
|
}
|
||||||
|
if (!parentBuilder.getFeatures().contains(SpecialFeature.SUBMAP)) {
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.INCLUSIVE));
|
||||||
|
}
|
||||||
|
#endignore
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE newBuilderUsing(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
return NAVIGABLE_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.NavigableMapGeneratorKV_BRACES(delegate, to, from));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TestSuite createDescendingSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||||
|
TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||||
|
|
||||||
|
List<Feature<?>> features = new ArrayList<>();
|
||||||
|
#ignore
|
||||||
|
features.add(SpecialFeature.DESCENDING);
|
||||||
|
features.addAll(parentBuilder.getFeatures());
|
||||||
|
features.remove(SpecialFeature.COPYING);
|
||||||
|
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||||
|
#endignore
|
||||||
|
return NAVIGABLE_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.DescendingTestMapGeneratorKV_BRACES(delegate))
|
||||||
|
.named(parentBuilder.getName() + " descending").withFeatures(features)
|
||||||
|
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator) {
|
||||||
|
return NAVIGABLE_SET_TEST_BUILDER.using((TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE) keySetGenerator);
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder.maps;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.testers.PACKAGE.builder.ORDERED_SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
|
||||||
|
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||||
|
import speiger.src.testers.objects.builder.ObjectOrderedSetTestSuiteBuilder;
|
||||||
|
import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) {
|
||||||
|
return (ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = super.getTesters();
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class);
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite createTestSuite() {
|
||||||
|
#ignore
|
||||||
|
withFeatures(CollectionFeature.KNOWN_ORDER);
|
||||||
|
#endignore
|
||||||
|
return super.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectSetTestSuiteBuilder<MAP.Entry KEY_VALUE_GENERIC_TYPE> createDerivedEntrySetSuite(TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySetGenerator) {
|
||||||
|
return ObjectOrderedSetTestSuiteBuilder.using((TestObjectOrderedSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySetGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||||
|
return ORDERED_SET_TEST_BUILDER.using((TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE)generator);
|
||||||
|
}
|
||||||
|
}
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.builder.maps;
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER;
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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.features.Feature;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPESortedMapNavigationTester;
|
||||||
|
import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.builder.SORTED_SET_TEST_BUILDER;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.utils.SpecialFeature;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE {
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) {
|
||||||
|
return (SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||||
|
List<Class<? extends AbstractTester>> testers = super.getTesters();
|
||||||
|
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPESortedMapNavigationTester.class);
|
||||||
|
return testers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite createTestSuite() {
|
||||||
|
#ignore
|
||||||
|
if (!getFeatures().contains(KNOWN_ORDER)) {
|
||||||
|
List<Feature<?>> features = Helpers.copyToList(getFeatures());
|
||||||
|
features.add(KNOWN_ORDER);
|
||||||
|
withFeatures(features);
|
||||||
|
}
|
||||||
|
#endignore
|
||||||
|
return super.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||||
|
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||||
|
#ignore
|
||||||
|
if (!parentBuilder.getFeatures().contains(SpecialFeature.SUBMAP)) {
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND));
|
||||||
|
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE));
|
||||||
|
}
|
||||||
|
#endignore
|
||||||
|
return derivedSuites;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator) {
|
||||||
|
return keySetGenerator instanceof TEST_SORTED_SET_GENERATOR ? SORTED_SET_TEST_BUILDER.using((TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE) keySetGenerator) : SET_TEST_BUILDER.using(keySetGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestSuite createSubmapSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder, Bound from, Bound to) {
|
||||||
|
TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||||
|
List<Feature<?>> features = new ArrayList<>();
|
||||||
|
#ignore
|
||||||
|
features.add(SpecialFeature.SUBMAP);
|
||||||
|
features.addAll(parentBuilder.getFeatures());
|
||||||
|
features.remove(SpecialFeature.COPYING);
|
||||||
|
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
return newBuilderUsing(delegate, to, from).named(parentBuilder.getName() + " subMap " + from + "-" + to)
|
||||||
|
.withFeatures(features).suppressing(parentBuilder.getSuppressedTests())
|
||||||
|
.withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE newBuilderUsing(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
return using(new DERIVED_MAP_GENERATORS.SortedMapGeneratorKV_BRACES(delegate, to, from));
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.TestCollectionGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE extends TestCollectionGenerator<CLASS_TYPE>
|
||||||
|
{
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples();
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
public COLLECTION KEY_GENERIC_TYPE create(KEY_TYPE...elements);
|
||||||
|
#endif
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public default SampleElements<CLASS_TYPE> samples() {return getSamples().toSamples();}
|
||||||
|
@Override
|
||||||
|
public COLLECTION KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
@Override
|
||||||
|
public default CLASS_TYPE[] createArray(int length) { return NEW_CLASS_ARRAY(length); }
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder);
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.TestListGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_LIST_GENERATOR KEY_GENERIC_TYPE extends TestListGenerator<CLASS_TYPE>, TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
LIST KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
LIST KEY_GENERIC_TYPE create(KEY_TYPE... elements);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements);
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements);
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.TestContainerGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE extends TestContainerGenerator<PRIORITY_QUEUE KEY_GENERIC_TYPE, CLASS_TYPE>
|
||||||
|
{
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples();
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE create(KEY_TYPE...elements);
|
||||||
|
#endif
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public default SampleElements<CLASS_TYPE> samples() {return getSamples().toSamples();}
|
||||||
|
@Override
|
||||||
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
@Override
|
||||||
|
public default CLASS_TYPE[] createArray(int length) { return NEW_CLASS_ARRAY(length); }
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder);
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.TestSetGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE, TestSetGenerator<CLASS_TYPE> {
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
SET KEY_GENERIC_TYPE create(KEY_TYPE...elements);
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
SET KEY_GENERIC_TYPE create(Object...elements);
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
SORTED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements);
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
SORTED_SET KEY_GENERIC_TYPE create(Object... elements);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an element less than the {@link #samples()} and less than {@link
|
||||||
|
* #belowSamplesGreater()}.
|
||||||
|
*/
|
||||||
|
KEY_TYPE belowSamplesLesser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an element less than the {@link #samples()} but greater than {@link
|
||||||
|
* #belowSamplesLesser()}.
|
||||||
|
*/
|
||||||
|
KEY_TYPE belowSamplesGreater();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an element greater than the {@link #samples()} but less than {@link
|
||||||
|
* #aboveSamplesGreater()}.
|
||||||
|
*/
|
||||||
|
KEY_TYPE aboveSamplesLesser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an element greater than the {@link #samples()} and greater than {@link
|
||||||
|
* #aboveSamplesLesser()}.
|
||||||
|
*/
|
||||||
|
KEY_TYPE aboveSamplesGreater();
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators.maps;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.Helpers;
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.TestMapGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectList;
|
||||||
|
import speiger.src.testers.objects.utils.ObjectSamples;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TestMapGenerator<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||||
|
public ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE> getSamples();
|
||||||
|
public ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> insertionOrder);
|
||||||
|
public MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements);
|
||||||
|
@Override
|
||||||
|
default MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE[] result = new MAP.Entry[elements.length];
|
||||||
|
for(int i = 0;i<elements.length;i++) {
|
||||||
|
result[i] = (MAP.Entry KEY_VALUE_GENERIC_TYPE) elements[i];
|
||||||
|
}
|
||||||
|
return create(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default CLASS_TYPE[] createKeyArray(int length) { return NEW_CLASS_ARRAY(length); }
|
||||||
|
@Override
|
||||||
|
default CLASS_VALUE_TYPE[] createValueArray(int length) { return NEW_CLASS_VALUE_ARRAY(length); }
|
||||||
|
@Override
|
||||||
|
default MAP.Entry KEY_VALUE_GENERIC_TYPE[] createArray(int length) { return new MAP.Entry[length]; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default SampleElements<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> samples() {
|
||||||
|
ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE> samples = getSamples();
|
||||||
|
return new SampleElements<>(
|
||||||
|
Helpers.mapEntry(samples.e0().ENTRY_KEY(), samples.e0().ENTRY_VALUE()),
|
||||||
|
Helpers.mapEntry(samples.e1().ENTRY_KEY(), samples.e1().ENTRY_VALUE()),
|
||||||
|
Helpers.mapEntry(samples.e2().ENTRY_KEY(), samples.e2().ENTRY_VALUE()),
|
||||||
|
Helpers.mapEntry(samples.e3().ENTRY_KEY(), samples.e3().ENTRY_VALUE()),
|
||||||
|
Helpers.mapEntry(samples.e4().ENTRY_KEY(), samples.e4().ENTRY_VALUE())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators.maps;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
default ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) { return (ORDERED_MAP KEY_VALUE_GENERIC_TYPE) TEST_MAP_GENERATOR.super.create(elements); }
|
||||||
|
@Override
|
||||||
|
ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements);
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.generators.maps;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.TestSortedMapGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public interface TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE, TestSortedMapGenerator<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
default SORTED_MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) { return (SORTED_MAP KEY_VALUE_GENERIC_TYPE) TEST_MAP_GENERATOR.super.create(elements); }
|
||||||
|
@Override
|
||||||
|
SORTED_MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser();
|
||||||
|
@Override
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater();
|
||||||
|
@Override
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser();
|
||||||
|
@Override
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater();
|
||||||
|
}
|
||||||
+314
@@ -0,0 +1,314 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl;
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Objects;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.COPY_ON_WRITE_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.IMMUTABLE_LIST;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.RB_TREE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.IMMUTABLE_HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
|
#endif
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.StringSortTest;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionConstructorTester;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class COLLECTION_CONSTRUCTOR_TESTS
|
||||||
|
{
|
||||||
|
public static class ArrayList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ArrayList() {
|
||||||
|
setSimpleConstructor(ARRAY_LIST::new);
|
||||||
|
setSizeConstructor(T -> new ARRAY_LISTBRACES(T));
|
||||||
|
setPArrayConstructor(T -> new ARRAY_LISTBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new ARRAY_LISTBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new ARRAY_LISTBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public LinkedList() {
|
||||||
|
setSimpleConstructor(LINKED_LIST::new);
|
||||||
|
setPArrayConstructor(T -> new LINKED_LISTBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new LINKED_LISTBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new LINKED_LISTBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CopyOnWriteArrayList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CopyOnWriteArrayList() {
|
||||||
|
setSimpleConstructor(COPY_ON_WRITE_LIST::new);
|
||||||
|
setPArrayConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ImmutableList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ImmutableList() {
|
||||||
|
setPArrayConstructor(T -> new IMMUTABLE_LISTBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new IMMUTABLE_LISTBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new IMMUTABLE_LISTBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
public static class HashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public HashSet() {
|
||||||
|
setSimpleConstructor(HASH_SET::new);
|
||||||
|
setSizeConstructor(T -> new HASH_SETBRACES(T));
|
||||||
|
setPArrayConstructor(T -> new HASH_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new HASH_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new HASH_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public LinkedHashSet() {
|
||||||
|
setSimpleConstructor(LINKED_HASH_SET::new);
|
||||||
|
setSizeConstructor(T -> new LINKED_HASH_SETBRACES(T));
|
||||||
|
setPArrayConstructor(T -> new LINKED_HASH_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new LINKED_HASH_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new LINKED_HASH_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CustomHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public CustomHashSet() {
|
||||||
|
setSimpleConstructor(() -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setPCollectionConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setCollectionConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedCustomHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public LinkedCustomHashSet() {
|
||||||
|
setSimpleConstructor(() -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setPCollectionConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
setCollectionConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ImmutableHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ImmutableHashSet() {
|
||||||
|
setPArrayConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArraySet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public ArraySet() {
|
||||||
|
setSimpleConstructor(ARRAY_SET::new);
|
||||||
|
setSizeConstructor(T -> new ARRAY_SETBRACES(T));
|
||||||
|
setPArrayConstructor(T -> new ARRAY_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new ARRAY_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new ARRAY_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public RBTreeSet() {
|
||||||
|
setSimpleConstructor(RB_TREE_SET::new);
|
||||||
|
setPArrayConstructor(T -> new RB_TREE_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new RB_TREE_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new RB_TREE_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public AVLTreeSet() {
|
||||||
|
setSimpleConstructor(AVL_TREE_SET::new);
|
||||||
|
setPArrayConstructor(T -> new AVL_TREE_SETBRACES(T));
|
||||||
|
setPCollectionConstructor(T -> new AVL_TREE_SETBRACES(T));
|
||||||
|
setCollectionConstructor(T -> new AVL_TREE_SETBRACES(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeSetComparator extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public RBTreeSetComparator() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> new RB_TREE_SET<String>(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
setPCollectionConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
setCollectionConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> new RB_TREE_SET(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
setPCollectionConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
setCollectionConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeSetComparator extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public AVLTreeSetComparator() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> new AVL_TREE_SET<String>(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
setPCollectionConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
setCollectionConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> new AVL_TREE_SET(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
setPCollectionConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
setCollectionConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class HashStrategy implements STRATEGY KEY_STRING_GENERIC_TYPE {
|
||||||
|
static final HashStrategy INSTANCE = new HashStrategy();
|
||||||
|
@Override
|
||||||
|
public int hashCode(KEY_STRING_TYPE o) { return KEY_TO_HASH(o); }
|
||||||
|
@Override
|
||||||
|
public boolean equals(KEY_STRING_TYPE key, KEY_STRING_TYPE value) { return KEY_EQUALS(key, value); }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SIMPLE_QUEUE_TEST_GENERATOR KEY_GENERIC_TYPE implements TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
Function<KEY_TYPE[], PRIORITY_QUEUE KEY_GENERIC_TYPE> mapper;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
KEY_TYPE[] keys;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public SIMPLE_QUEUE_TEST_GENERATOR(Function<KEY_TYPE[], PRIORITY_QUEUE KEY_GENERIC_TYPE> mapper) {
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public SIMPLE_QUEUE_TEST_GENERATOR KEY_GENERIC_TYPE setElements(KEY_TYPE...keys) {
|
||||||
|
this.keys = keys;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
return new SAMPLE_ELEMENTS(true, false, true, false, true);
|
||||||
|
#else if TYPE_BYTE
|
||||||
|
return new SAMPLE_ELEMENTS((byte)0, (byte)1, (byte)2, (byte)3, (byte)4);
|
||||||
|
#else if TYPE_SHORT
|
||||||
|
return new SAMPLE_ELEMENTS((short)0, (short)1, (short)2, (short)3, (short)4);
|
||||||
|
#else if TYPE_CHAR
|
||||||
|
return new SAMPLE_ELEMENTS((char)0, (char)1, (char)2, (char)3, (char)4);
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
return new SAMPLE_ELEMENTSBRACES(keys[0], keys[1], keys[2], keys[3], keys[4]);
|
||||||
|
#else
|
||||||
|
return new SAMPLE_ELEMENTS(0, 1, 2, 3, 4);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return mapper.apply(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PRIORITY_QUEUE 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 mapper.apply(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
T[] array = (T[])ObjectArrays.newArray(keys[0].getClass(), elements.length);
|
||||||
|
int i = 0;
|
||||||
|
for (Object e : elements) {
|
||||||
|
array[i++] = CLASS_TO_KEY(e);
|
||||||
|
}
|
||||||
|
return mapper.apply(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
+221
@@ -0,0 +1,221 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_LIST_GENERATOR;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<E extends COLLECTION KEY_GENERIC_TYPE> {
|
||||||
|
Function<KEY_TYPE[], E> mapper;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
KEY_TYPE[] keys;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public SIMPLE_TEST_GENERATOR(Function<KEY_TYPE[], E> mapper) {
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<E> setElements(KEY_TYPE...keys) {
|
||||||
|
this.keys = keys;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
return new SAMPLE_ELEMENTS(true, false, true, false, true);
|
||||||
|
#else if TYPE_BYTE
|
||||||
|
return new SAMPLE_ELEMENTS((byte)0, (byte)1, (byte)2, (byte)3, (byte)4);
|
||||||
|
#else if TYPE_SHORT
|
||||||
|
return new SAMPLE_ELEMENTS((short)0, (short)1, (short)2, (short)3, (short)4);
|
||||||
|
#else if TYPE_CHAR
|
||||||
|
return new SAMPLE_ELEMENTS((char)0, (char)1, (char)2, (char)3, (char)4);
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
return new SAMPLE_ELEMENTSBRACES(keys[0], keys[1], keys[2], keys[3], keys[4]);
|
||||||
|
#else
|
||||||
|
return new SAMPLE_ELEMENTS(0, 1, 2, 3, 4);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
public E create(KEY_TYPE... elements) {
|
||||||
|
return mapper.apply(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
public E 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 mapper.apply(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
public E create(Object... elements) {
|
||||||
|
T[] array = (T[])ObjectArrays.newArray(keys[0].getClass(), elements.length);
|
||||||
|
int i = 0;
|
||||||
|
for (Object e : elements) {
|
||||||
|
array[i++] = CLASS_TO_KEY(e);
|
||||||
|
}
|
||||||
|
return mapper.apply(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Collections KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<COLLECTION KEY_GENERIC_TYPE> implements TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public Collections(Function<KEY_TYPE[], COLLECTION KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Lists KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<LIST KEY_GENERIC_TYPE> implements TEST_LIST_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public Lists(Function<KEY_TYPE[], LIST KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
public static class Sets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<SET KEY_GENERIC_TYPE> implements TEST_SET_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public Sets(Function<KEY_TYPE[], SET KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OrderedSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<ORDERED_SET KEY_GENERIC_TYPE> implements TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public OrderedSets(Function<KEY_TYPE[], ORDERED_SET KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SortedSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<SORTED_SET KEY_GENERIC_TYPE> implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public SortedSets(Function<KEY_TYPE[], SORTED_SET KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
insertionOrder.sort(null);
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
insertionOrder.sort(null);
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_CHAR
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return '_'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return '`'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return 'f'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return 'g'; }
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return keys[5]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return keys[6]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return keys[7]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return keys[8]; }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return -2; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return -1; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return 5; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return 6; }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class NavigableSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE<NAVIGABLE_SET KEY_GENERIC_TYPE> implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public NavigableSets(Function<KEY_TYPE[], NAVIGABLE_SET KEY_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
insertionOrder.sort(null);
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
insertionOrder.sort(null);
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_CHAR
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { return new SAMPLE_ELEMENTS('a', 'b', 'c', 'd', 'e'); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return '_'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return '`'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return 'f'; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return 'g'; }
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return keys[5]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return keys[6]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return keys[7]; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return keys[8]; }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() { return -2; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() { return -1; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() { return 5; }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() { return 6; }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl;
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.Comparator;
|
||||||
|
#endif
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.DerivedCollectionGenerators.Bound;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
|
#endif
|
||||||
|
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.sets.SORTED_SET;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SUB_SORTED_SET_CLASS_GENERATOR KEY_GENERIC_TYPE implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
final Bound to;
|
||||||
|
final Bound from;
|
||||||
|
final KEY_TYPE firstInclusive;
|
||||||
|
final KEY_TYPE lastInclusive;
|
||||||
|
private final COMPARATOR KEY_GENERIC_TYPE comparator;
|
||||||
|
private final TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate;
|
||||||
|
|
||||||
|
public SUB_SORTED_SET_CLASS_GENERATOR(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
this.to = to;
|
||||||
|
this.from = from;
|
||||||
|
this.delegate = delegate;
|
||||||
|
|
||||||
|
SORTED_SET KEY_GENERIC_TYPE emptySet = delegate.create(NEW_KEY_ARRAY(0));
|
||||||
|
comparator = emptySet.comparator();
|
||||||
|
|
||||||
|
SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples = delegate.getSamples();
|
||||||
|
LIST KEY_GENERIC_TYPE samplesList = new ARRAY_LISTBRACES(samples.asList());
|
||||||
|
samplesList.sort(comparator);
|
||||||
|
firstInclusive = samplesList.GET_KEY(0);
|
||||||
|
lastInclusive = samplesList.GET_KEY(samplesList.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE getInnerGenerator() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Bound getTo() {
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Bound getFrom() {
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
|
||||||
|
SORTED_SET KEY_GENERIC_TYPE createSubSet(SORTED_SET KEY_GENERIC_TYPE set, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) {
|
||||||
|
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
|
||||||
|
return set.headSet(lastExclusive);
|
||||||
|
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
|
||||||
|
return set.tailSet(firstInclusive);
|
||||||
|
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
|
||||||
|
return set.subSet(firstInclusive, lastExclusive);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
return delegate.getSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
return delegate.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
return delegate.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE create(KEY_OBJECT_TYPE... elements) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
LIST KEY_GENERIC_TYPE normalValues = (LIST KEY_GENERIC_TYPE)ARRAY_LIST.wrap(elements);
|
||||||
|
#else
|
||||||
|
LIST KEY_GENERIC_TYPE normalValues = ARRAY_LIST.wrap(elements);
|
||||||
|
#endif
|
||||||
|
LIST KEY_GENERIC_TYPE extremeValues = new ARRAY_LISTBRACES();
|
||||||
|
KEY_TYPE firstExclusive = delegate.belowSamplesGreater();
|
||||||
|
KEY_TYPE lastExclusive = delegate.aboveSamplesLesser();
|
||||||
|
if (from != Bound.NO_BOUND) {
|
||||||
|
extremeValues.add(delegate.belowSamplesLesser());
|
||||||
|
extremeValues.add(delegate.belowSamplesGreater());
|
||||||
|
}
|
||||||
|
if (to != Bound.NO_BOUND) {
|
||||||
|
extremeValues.add(delegate.aboveSamplesLesser());
|
||||||
|
extremeValues.add(delegate.aboveSamplesGreater());
|
||||||
|
}
|
||||||
|
LIST KEY_GENERIC_TYPE allEntries = new ARRAY_LISTBRACES();
|
||||||
|
allEntries.addAll(extremeValues);
|
||||||
|
allEntries.addAll(normalValues);
|
||||||
|
SORTED_SET KEY_GENERIC_TYPE set = delegate.create(allEntries.toArray());
|
||||||
|
|
||||||
|
return createSubSet(set, firstExclusive, lastExclusive);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public SORTED_SET 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public static final class SUB_NAVIGABLE_SET_CLASS_GENERATOR KEY_GENERIC_TYPE extends SUB_SORTED_SET_CLASS_GENERATOR KEY_GENERIC_TYPE implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
public SUB_NAVIGABLE_SET_CLASS_GENERATOR(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) {
|
||||||
|
super(delegate, to, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
NAVIGABLE_SET KEY_GENERIC_TYPE createSubSet(SORTED_SET KEY_GENERIC_TYPE sortedSet, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) {
|
||||||
|
NAVIGABLE_SET KEY_GENERIC_TYPE set = (NAVIGABLE_SET KEY_GENERIC_TYPE) sortedSet;
|
||||||
|
if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) return set.headSet(lastInclusive, true);
|
||||||
|
else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) return set.tailSet(firstExclusive, false);
|
||||||
|
else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) return set.subSet(firstExclusive, false, lastExclusive, false);
|
||||||
|
else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) return set.subSet(firstExclusive, false, lastInclusive, true);
|
||||||
|
else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) return set.subSet(firstInclusive, true, lastInclusive, true);
|
||||||
|
return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.createSubSet(set, firstExclusive, lastExclusive);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+550
@@ -0,0 +1,550 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl.maps;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
import java.util.Objects;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.DerivedCollectionGenerators.Bound;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||||
|
#if !VALUE_OBJECT && !SAME_TYPE
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERABLE;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_COMPARATOR;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.generators.VALUE_TEST_COLLECTION_GENERATOR;
|
||||||
|
#if !VALUE_OBJECT && !SAME_TYPE
|
||||||
|
import speiger.src.testers.VALUE_PACKAGE.utils.VALUE_SAMPLE_ELEMENTS;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectList;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectLists;
|
||||||
|
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator;
|
||||||
|
#endif
|
||||||
|
import speiger.src.testers.objects.utils.ObjectSamples;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class DERIVED_MAP_GENERATORS {
|
||||||
|
public static class NavigableMapGenerator KEY_VALUE_GENERIC_TYPE extends SortedMapGenerator KEY_VALUE_GENERIC_TYPE {
|
||||||
|
public NavigableMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent, Bound to, Bound from) {
|
||||||
|
super(parent, to, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE createSubMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE sortedMap, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) {
|
||||||
|
NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map = (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) sortedMap;
|
||||||
|
if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
|
||||||
|
return map.headMap(lastInclusive, true);
|
||||||
|
} else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
|
||||||
|
return map.tailMap(firstExclusive, false);
|
||||||
|
} else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
|
||||||
|
return map.subMap(firstExclusive, false, lastExclusive, false);
|
||||||
|
} else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
|
||||||
|
return map.subMap(firstExclusive, false, lastInclusive, true);
|
||||||
|
} else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
|
||||||
|
return map.subMap(firstInclusive, true, lastInclusive, true);
|
||||||
|
} else {
|
||||||
|
return (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) super.createSubMap(map, firstExclusive, lastExclusive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SortedMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE {
|
||||||
|
TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||||
|
Bound to;
|
||||||
|
Bound from;
|
||||||
|
KEY_TYPE firstInclusive;
|
||||||
|
KEY_TYPE lastInclusive;
|
||||||
|
Comparator<Entry KEY_VALUE_GENERIC_TYPE> entryComparator;
|
||||||
|
|
||||||
|
public SortedMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent, Bound to, Bound from) {
|
||||||
|
super(parent);
|
||||||
|
this.parent = parent;
|
||||||
|
this.to = to;
|
||||||
|
this.from = from;
|
||||||
|
SORTED_MAP KEY_VALUE_GENERIC_TYPE map = parent.create();
|
||||||
|
entryComparator = DERIVED_MAP_GENERATORS.entryComparator(map.comparator());
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> samples = parent.getSamples().asList();
|
||||||
|
samples.sort(entryComparator);
|
||||||
|
firstInclusive = samples.get(0).ENTRY_KEY();
|
||||||
|
lastInclusive = samples.get(samples.size() - 1).ENTRY_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> entries = new ObjectArrayList<>();
|
||||||
|
if (from != Bound.NO_BOUND) {
|
||||||
|
entries.add(parent.belowSamplesLesser());
|
||||||
|
entries.add(parent.belowSamplesGreater());
|
||||||
|
}
|
||||||
|
if (to != Bound.NO_BOUND) {
|
||||||
|
entries.add(parent.aboveSamplesLesser());
|
||||||
|
entries.add(parent.aboveSamplesGreater());
|
||||||
|
}
|
||||||
|
entries.addAll(elements);
|
||||||
|
return createSubMap(parent.create(entries.toArray(Entry[]::new)), parent.belowSamplesGreater().ENTRY_KEY(), parent.aboveSamplesLesser().ENTRY_KEY());
|
||||||
|
}
|
||||||
|
|
||||||
|
SORTED_MAP KEY_VALUE_GENERIC_TYPE createSubMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) {
|
||||||
|
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
|
||||||
|
return map.headMap(lastExclusive);
|
||||||
|
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
|
||||||
|
return map.tailMap(firstInclusive);
|
||||||
|
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
|
||||||
|
return map.subMap(firstInclusive, lastExclusive);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DescendingTestMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||||
|
|
||||||
|
public DescendingTestMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) {
|
||||||
|
super(parent);
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||||
|
return ((NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE)parent.create(elements)).descendingMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> order(List<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> insertionOrder) {
|
||||||
|
ObjectList<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> values = ObjectIterators.pour(ObjectIterators.wrap(parent.order(insertionOrder).iterator()));
|
||||||
|
ObjectLists.reverse(values);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIterable<Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> values = parent.order(insertionOrder).pourAsList();
|
||||||
|
ObjectLists.reverse(values);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() {
|
||||||
|
return parent.aboveSamplesGreater();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() {
|
||||||
|
return parent.aboveSamplesLesser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() {
|
||||||
|
return parent.belowSamplesGreater();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() {
|
||||||
|
return parent.belowSamplesLesser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||||
|
|
||||||
|
public MapGenerator(TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> order(List<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> insertionOrder) {
|
||||||
|
return parent.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectSamples<Entry KEY_VALUE_GENERIC_TYPE> getSamples() {
|
||||||
|
return parent.getSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIterable<Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
return parent.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||||
|
return parent.create(elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
if(inner.getInnerGenerator() instanceof TEST_ORDERED_MAP_GENERATOR) {
|
||||||
|
ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> set = ((TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().ENTRY_SET();
|
||||||
|
if(set instanceof ObjectOrderedSet) return new OrderedMapEntrySetGeneratorKV_BRACES(inner);
|
||||||
|
}
|
||||||
|
return new MapEntrySetGeneratorKV_BRACES(inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OrderedMapEntrySetGenerator KEY_VALUE_GENERIC_TYPE extends MapEntrySetGenerator KEY_VALUE_GENERIC_TYPE implements TestObjectOrderedSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
|
|
||||||
|
public OrderedMapEntrySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
super(inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectOrderedSet<Entry KEY_VALUE_GENERIC_TYPE> create(Object... elements) {
|
||||||
|
return (ObjectOrderedSet<Entry KEY_VALUE_GENERIC_TYPE>)super.create(elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapEntrySetGenerator KEY_VALUE_GENERIC_TYPE implements TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
|
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator;
|
||||||
|
|
||||||
|
public MapEntrySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectSamples<Entry KEY_VALUE_GENERIC_TYPE> getSamples() {
|
||||||
|
return generator.getSamples();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIterable<Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
return generator.order(insertionOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Entry KEY_VALUE_GENERIC_TYPE> order(List<Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
return generator.order(new ObjectArrayList<Entry KEY_VALUE_GENERIC_TYPE>(insertionOrder));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry KEY_VALUE_GENERIC_TYPE[] createArray(int length) {
|
||||||
|
return new Entry[length];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectSet<Entry KEY_VALUE_GENERIC_TYPE> create(Object... elements) {
|
||||||
|
return generator.create(elements).ENTRY_SET();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
if (inner.getInnerGenerator() instanceof TEST_SORTED_MAP_GENERATOR) {
|
||||||
|
SET KEY_GENERIC_TYPE set = ((TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().keySet();
|
||||||
|
if(set instanceof NAVIGABLE_SET) return new MapNavigableKeySetGeneratorKV_BRACES(inner);
|
||||||
|
if(set instanceof SORTED_SET) return new MapSortedKeySetGeneratorKV_BRACES(inner);
|
||||||
|
}
|
||||||
|
if(inner.getInnerGenerator() instanceof TEST_ORDERED_MAP_GENERATOR) {
|
||||||
|
SET KEY_GENERIC_TYPE set = ((TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().keySet();
|
||||||
|
if(set instanceof ORDERED_SET) return new MapOrderedKeySetGeneratorKV_BRACES(inner);
|
||||||
|
}
|
||||||
|
return new MapKeySetGeneratorKV_BRACES(inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapNavigableKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapSortedKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
public MapNavigableKeySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
super(inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return (NAVIGABLE_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
return (NAVIGABLE_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapSortedKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator;
|
||||||
|
|
||||||
|
public MapSortedKeySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
super(inner);
|
||||||
|
generator = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return (SORTED_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
return (SORTED_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesLesser() {
|
||||||
|
return generator.belowSamplesLesser().ENTRY_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE belowSamplesGreater() {
|
||||||
|
return generator.belowSamplesGreater().ENTRY_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesLesser() {
|
||||||
|
return generator.aboveSamplesLesser().ENTRY_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE aboveSamplesGreater() {
|
||||||
|
return generator.aboveSamplesGreater().ENTRY_KEY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapOrderedKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
|
||||||
|
public MapOrderedKeySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
super(inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
return (ORDERED_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
return (ORDERED_SET KEY_GENERIC_TYPE) super.create(elements);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SET_GENERATOR KEY_GENERIC_TYPE {
|
||||||
|
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator;
|
||||||
|
SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples;
|
||||||
|
|
||||||
|
public MapKeySetGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator();
|
||||||
|
ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE> samples = generator.getSamples();
|
||||||
|
this.samples = new SAMPLE_ELEMENTSBRACES(samples.e0().ENTRY_KEY(), samples.e1().ENTRY_KEY(), samples.e2().ENTRY_KEY(), samples.e3().ENTRY_KEY(), samples.e4().ENTRY_KEY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||||
|
VALUE_TYPE value = generator.getSamples().e0().ENTRY_VALUE();
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> entries = new ObjectArrayList<>();
|
||||||
|
for (KEY_TYPE key : insertionOrder) {
|
||||||
|
entries.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(key, value));
|
||||||
|
}
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.order(entries)) {
|
||||||
|
list.add(entry.ENTRY_KEY());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||||
|
VALUE_TYPE value = generator.getSamples().e0().ENTRY_VALUE();
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> entries = new ObjectArrayList<>();
|
||||||
|
for (KEY_TYPE key : insertionOrder) {
|
||||||
|
entries.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(key, value));
|
||||||
|
}
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.order(entries)) {
|
||||||
|
list.add(entry.ENTRY_KEY());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length];
|
||||||
|
int index = 0;
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) {
|
||||||
|
result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES(elements[index++], entry.ENTRY_VALUE());
|
||||||
|
}
|
||||||
|
return generator.create(result).keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length];
|
||||||
|
int index = 0;
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) {
|
||||||
|
result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES((CLASS_TYPE) elements[index++], entry.getValue());
|
||||||
|
}
|
||||||
|
return generator.create(result).keySet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MapValueCollectionGenerator KEY_VALUE_GENERIC_TYPE implements VALUE_TEST_COLLECTION_GENERATOR VALUE_GENERIC_TYPE {
|
||||||
|
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator;
|
||||||
|
VALUE_SAMPLE_ELEMENTS VALUE_GENERIC_TYPE samples;
|
||||||
|
|
||||||
|
public MapValueCollectionGenerator(OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> inner) {
|
||||||
|
generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator();
|
||||||
|
ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE> samples = generator.getSamples();
|
||||||
|
this.samples = new VALUE_SAMPLE_ELEMENTSVALUE_BRACES(samples.e0().ENTRY_VALUE(), samples.e1().ENTRY_VALUE(), samples.e2().ENTRY_VALUE(), samples.e3().ENTRY_VALUE(), samples.e4().ENTRY_VALUE());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_SAMPLE_ELEMENTS VALUE_GENERIC_TYPE getSamples() {
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_ITERABLE VALUE_GENERIC_TYPE order(VALUE_LIST VALUE_GENERIC_TYPE insertionOrder) {
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> list = generator.order(generator.getSamples().asList()).pourAsList();
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
insertionOrder.sort(new Comparator<VALUE_TYPE>() {
|
||||||
|
#else
|
||||||
|
insertionOrder.sort(new VALUE_COMPARATOR VALUE_GENERIC_TYPE() {
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public int compare(VALUE_TYPE key, VALUE_TYPE value) {
|
||||||
|
return Integer.signum(indexOf(key) - indexOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int indexOf(VALUE_TYPE entry) {
|
||||||
|
for(int i = 0,m=list.size();i<m;i++) {
|
||||||
|
if(VALUE_EQUALS(list.get(i).ENTRY_VALUE(), entry)) return i;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("MAP.values generator can order only sample values");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<CLASS_VALUE_TYPE> order(List<CLASS_VALUE_TYPE> insertionOrder) {
|
||||||
|
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> list = generator.order(generator.getSamples().asList()).pourAsList();
|
||||||
|
insertionOrder.sort(new Comparator<CLASS_VALUE_TYPE>() {
|
||||||
|
@Override
|
||||||
|
public int compare(CLASS_VALUE_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
|
return Integer.signum(indexOf(key) - indexOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int indexOf(CLASS_VALUE_TYPE entry) {
|
||||||
|
for(int i = 0,m=list.size();i<m;i++) {
|
||||||
|
if(VALUE_EQUALS(list.get(i).ENTRY_VALUE(), OBJ_TO_VALUE(entry))) return i;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("MAP.values generator can order only sample values");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_COLLECTION VALUE_GENERIC_TYPE create(VALUE_TYPE... elements) {
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length];
|
||||||
|
int index = 0;
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) {
|
||||||
|
result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES(entry.ENTRY_KEY(), elements[index++]);
|
||||||
|
}
|
||||||
|
return generator.create(result).values();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_COLLECTION VALUE_GENERIC_TYPE create(Object... elements) {
|
||||||
|
Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length];
|
||||||
|
int index = 0;
|
||||||
|
for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) {
|
||||||
|
result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES(entry.getKey(), (CLASS_VALUE_TYPE)elements[index++]);
|
||||||
|
}
|
||||||
|
return generator.create(result).values();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static KEY_VALUE_GENERIC_TYPE Comparator<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> entryObjectComparator(Comparator<CLASS_TYPE> keyComparator) {
|
||||||
|
return new Comparator<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> a, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> b) {
|
||||||
|
if(keyComparator == null) {
|
||||||
|
return COMPAREABLE_TO_KEY(OBJ_TO_KEY(a.getKey()), OBJ_TO_KEY(b.getKey()));
|
||||||
|
}
|
||||||
|
return keyComparator.compare(OBJ_TO_KEY(a.getKey()), OBJ_TO_KEY(b.getKey()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static KEY_VALUE_GENERIC_TYPE Comparator<Entry KEY_VALUE_GENERIC_TYPE> entryComparator(COMPARATOR KEY_GENERIC_TYPE keyComparator) {
|
||||||
|
return new Comparator<Entry KEY_VALUE_GENERIC_TYPE>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Entry KEY_VALUE_GENERIC_TYPE a, Entry KEY_VALUE_GENERIC_TYPE b) {
|
||||||
|
if(keyComparator == null) {
|
||||||
|
return COMPAREABLE_TO_KEY(a.ENTRY_KEY(), b.ENTRY_KEY());
|
||||||
|
}
|
||||||
|
return keyComparator.compare(a.ENTRY_KEY(), b.ENTRY_KEY());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+934
@@ -0,0 +1,934 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl.maps;
|
||||||
|
|
||||||
|
#if TYPE_OBJECT || VALUE_OBJECT
|
||||||
|
import java.util.Arrays;
|
||||||
|
#endif
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Comparator;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import org.junit.Assert;
|
||||||
|
#endif
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import com.google.common.collect.testing.AnEnum;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.customHash.CUSTOM_HASH_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
|
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester;
|
||||||
|
#if TYPE_OBJECT || VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.StringSortTest;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class MAP_CONSTRUCTOR_TESTS
|
||||||
|
{
|
||||||
|
public static class HashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public HashMap() {
|
||||||
|
setSimpleConstructor(MAP.builder()::map);
|
||||||
|
setSizeConstructor(MAP.builder()::map);
|
||||||
|
setPArrayConstructor(MAP.builder()::map);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(MAP.builder()::map);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(MAP.builder()::map);
|
||||||
|
setMapConstructor(MAP.builder()::map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongLoadFactorSize() {
|
||||||
|
setSizeConstructor(T -> new HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 1 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public LinkedHashMap() {
|
||||||
|
setSimpleConstructor(MAP.builder()::linkedMap);
|
||||||
|
setSizeConstructor(MAP.builder()::linkedMap);
|
||||||
|
setPArrayConstructor(MAP.builder()::linkedMap);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(MAP.builder()::linkedMap);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(MAP.builder()::linkedMap);
|
||||||
|
setMapConstructor(MAP.builder()::linkedMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongLoadFactorSize() {
|
||||||
|
setSizeConstructor(T -> new LINKED_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new LINKED_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 1 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
public static class EnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester<AnEnum, String>
|
||||||
|
#else
|
||||||
|
public static class EnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester<AnEnum>
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
public EnumMap() {
|
||||||
|
setSimpleConstructor(() -> new ENUM_MAP<>(AnEnum.class));
|
||||||
|
setPArrayConstructor(ENUM_MAP::new);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(ENUM_MAP::new);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(ENUM_MAP::new);
|
||||||
|
setMapConstructor(ENUM_MAP::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumMapConstructor() {
|
||||||
|
if(pMapConstructor == null) return;
|
||||||
|
Assert.assertTrue(pMapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testObjectEnumMapConstructor() {
|
||||||
|
if(pMapConstructor == null) return;
|
||||||
|
Assert.assertTrue(mapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AnEnum[] createKeyElements() {
|
||||||
|
return AnEnum.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOf(StringSortTest.NAMES, AnEnum.values().length);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
protected int getSize() {
|
||||||
|
return AnEnum.values().length;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
public static class LinkedEnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester<AnEnum, String>
|
||||||
|
#else
|
||||||
|
public static class LinkedEnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester<AnEnum>
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
public LinkedEnumMap() {
|
||||||
|
setSimpleConstructor(() -> new LINKED_ENUM_MAP<>(AnEnum.class));
|
||||||
|
setPArrayConstructor(LINKED_ENUM_MAP::new);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(LINKED_ENUM_MAP::new);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(LINKED_ENUM_MAP::new);
|
||||||
|
setMapConstructor(LINKED_ENUM_MAP::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnumMapConstructor() {
|
||||||
|
if(pMapConstructor == null) return;
|
||||||
|
Assert.assertTrue(pMapConstructor.apply(new LINKED_ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
Assert.assertTrue(pMapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testObjectEnumMapConstructor() {
|
||||||
|
if(mapConstructor == null) return;
|
||||||
|
Assert.assertTrue(mapConstructor.apply(new LINKED_ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
Assert.assertTrue(mapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AnEnum[] createKeyElements() {
|
||||||
|
return AnEnum.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOf(StringSortTest.NAMES, AnEnum.values().length);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
protected int getSize() {
|
||||||
|
return AnEnum.values().length;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public static class CustomHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public CustomHashMap() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder().customMap(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().customMap(K, V, HashStrategy.INSTANCE));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().customMap(K, V, HashStrategy.INSTANCE));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE));
|
||||||
|
setMapConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongLoadFactorSize() {
|
||||||
|
setSizeConstructor(T -> new CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F, HashStrategy.INSTANCE));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F, HashStrategy.INSTANCE));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 1 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedCustomHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public LinkedCustomHashMap() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder().customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().customLinkedMap(K, V, HashStrategy.INSTANCE));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().customLinkedMap(K, V, HashStrategy.INSTANCE));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE));
|
||||||
|
setMapConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongLoadFactorSize() {
|
||||||
|
setSizeConstructor(T -> new LINKED_CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F, HashStrategy.INSTANCE));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new LINKED_CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F, HashStrategy.INSTANCE));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 1 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ImmutableHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ImmutableHashMap() {
|
||||||
|
setPArrayConstructor(MAP.builder()::immutable);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(MAP.builder()::immutable);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(MAP.builder()::immutable);
|
||||||
|
setMapConstructor(MAP.builder()::immutable);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConcurrentHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ConcurrentHashMap() {
|
||||||
|
setSimpleConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
setSizeConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
setPArrayConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
setMapConstructor(CONCURRENT_HASH_MAP::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongLoadFactorSize() {
|
||||||
|
setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 1 LoadFactor should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongConcurrency() {
|
||||||
|
setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 0 Concurrency should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, Integer.MAX_VALUE));
|
||||||
|
try {
|
||||||
|
testSizeConstructor_smallSize();
|
||||||
|
fail("A Constructor using a 65536 or larger Concurrency should error");
|
||||||
|
} catch(IllegalStateException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArrayMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ArrayMap() {
|
||||||
|
setSimpleConstructor(MAP.builder()::arrayMap);
|
||||||
|
setSizeConstructor(MAP.builder()::arrayMap);
|
||||||
|
setPArrayConstructor(MAP.builder()::arrayMap);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(MAP.builder()::arrayMap);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(MAP.builder()::arrayMap);
|
||||||
|
setMapConstructor(MAP.builder()::arrayMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public RBTreeMap() {
|
||||||
|
setSimpleConstructor(MAP.builder()::rbTreeMap);
|
||||||
|
setPArrayConstructor(RB_TREE_MAP::new);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(RB_TREE_MAP::new);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(RB_TREE_MAP::new);
|
||||||
|
setMapConstructor(RB_TREE_MAP::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeMapComparator extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public RBTreeMapComparator() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPErbTreeMap(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, Comparator.naturalOrder()));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, Comparator.naturalOrder()));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().rbTreeMap(T, Comparator.naturalOrder()));
|
||||||
|
setMapConstructor(T -> MAP.builder().rbTreeMap(T, Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> MAP.builder().rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, CLASS_TYPE::compare));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().rbTreeMap(T, CLASS_TYPE::compare));
|
||||||
|
setMapConstructor(T -> MAP.builder().rbTreeMap(T, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public AVLTreeMap() {
|
||||||
|
setSimpleConstructor(MAP.builder()::avlTreeMap);
|
||||||
|
setPArrayConstructor(AVL_TREE_MAP::new);
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor(AVL_TREE_MAP::new);
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(AVL_TREE_MAP::new);
|
||||||
|
setMapConstructor(AVL_TREE_MAP::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeMapComparator extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public AVLTreeMapComparator() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEavlTreeMap(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, Comparator.naturalOrder()));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, Comparator.naturalOrder()));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().avlTreeMap(T, Comparator.naturalOrder()));
|
||||||
|
setMapConstructor(T -> MAP.builder().avlTreeMap(T, Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> MAP.builder().avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, CLASS_TYPE::compare));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder().avlTreeMap(T, CLASS_TYPE::compare));
|
||||||
|
setMapConstructor(T -> MAP.builder().avlTreeMap(T, CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class HashStrategy implements STRATEGY KEY_STRING_GENERIC_TYPE {
|
||||||
|
static final HashStrategy INSTANCE = new HashStrategy();
|
||||||
|
@Override
|
||||||
|
public int hashCode(KEY_STRING_TYPE o) { return KEY_TO_HASH(o); }
|
||||||
|
@Override
|
||||||
|
public boolean equals(KEY_STRING_TYPE key, KEY_STRING_TYPE value) { return KEY_EQUALS(key, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public HashMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().map());
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).map());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).map());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).map());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).map());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).map());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public LinkedHashMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().linkedMap());
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).linkedMap());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).linkedMap());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).linkedMap());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).linkedMap());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).linkedMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class CustomHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public CustomHashMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().customMap(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).customMap(HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customMap(HashStrategy.INSTANCE));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customMap(HashStrategy.INSTANCE));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customMap(HashStrategy.INSTANCE));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customMap(HashStrategy.INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LinkedCustomHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public LinkedCustomHashMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customLinkedMap(HashStrategy.INSTANCE));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ImmutableHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ImmutableHashMapBuilder() {
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).immutable());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).immutable());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).immutable());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).immutable());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConcurrentHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ConcurrentHashMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().concurrentMap());
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).concurrentMap());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).concurrentMap());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).concurrentMap());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).concurrentMap());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).concurrentMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArrayMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public ArrayMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().arrayMap());
|
||||||
|
setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).arrayMap());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).arrayMap());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).arrayMap());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).arrayMap());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).arrayMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public RBTreeMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RBTreeMapComparatorBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public RBTreeMapComparatorBuilder() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(Comparator.naturalOrder()));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(Comparator.naturalOrder()));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(Comparator.naturalOrder()));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public AVLTreeMapBuilder() {
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap());
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap());
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap());
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap());
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AVLTreeMapComparatorBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public AVLTreeMapComparatorBuilder() {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap(Comparator.naturalOrder()));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(Comparator.naturalOrder()));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(Comparator.naturalOrder()));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(Comparator.naturalOrder()));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createKeyElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
protected String[] createValueElements() {
|
||||||
|
return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE putAll(MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE cache, KEY_STRING_TYPE[] keys, VALUE_STRING_TYPE[] values) {
|
||||||
|
if(keys.length != values.length) throw new IllegalStateException("Keys & Values lengths must match");
|
||||||
|
for(int i = 0;i<keys.length;i++) {
|
||||||
|
cache.put(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
|
||||||
|
private static MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE putAll(MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE cache, CLASS_STRING_TYPE[] keys, CLASS_STRING_VALUE_TYPE[] values) {
|
||||||
|
if(keys.length != values.length) throw new IllegalStateException("Keys & Values lengths must match");
|
||||||
|
for(int i = 0;i<keys.length;i++) {
|
||||||
|
cache.put(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user