Compare commits
125
Commits
0.5.5
..
ca33c9eb9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca33c9eb9e | ||
|
|
b4374fdd4d | ||
|
|
455ee64a88 | ||
|
|
893b371017 | ||
|
|
5fa9baae7a | ||
|
|
70d565c785 | ||
|
|
5c27e332cd | ||
|
|
f2d919bae5 | ||
|
|
7d4c77332b | ||
|
|
d1186d4f82 | ||
|
|
3b8a02ac51 | ||
|
|
f356d4ab57 | ||
|
|
b07bc85114 | ||
|
|
c37746cd84 | ||
|
|
fb7c417394 | ||
|
|
ddc58ee221 | ||
|
|
8b5e5a75c1 | ||
|
|
c1862e6b05 | ||
|
|
c2c2780967 | ||
|
|
086d933a0d | ||
|
|
1e7da394a1 | ||
|
|
9eb220194f | ||
|
|
0baf141e4b | ||
|
|
569d4f5c86 | ||
|
|
36f24731b0 | ||
|
|
ea5ace0166 | ||
|
|
663809ff27 | ||
|
|
5d6adb5446 | ||
|
|
212ad1ace2 | ||
|
|
707827929a | ||
|
|
27ad01657d | ||
|
|
e7da7acc08 | ||
|
|
72943cb22c | ||
|
|
068cc4a4f7 | ||
|
|
31b34f5de1 | ||
|
|
4bded1af80 | ||
|
|
100c7fe260 | ||
|
|
04f628fcc1 | ||
|
|
5fa26bfbf3 | ||
|
|
4d3eaaf604 | ||
|
|
33ab7c48bf | ||
|
|
1f4784c75e | ||
|
|
ae5a4ea818 | ||
|
|
5d66f7b453 | ||
|
|
12af656150 | ||
|
|
603ff3df0f | ||
|
|
b712981718 | ||
|
|
863d1a1027 | ||
|
|
6287da8efe | ||
|
|
c27e852ccb | ||
|
|
0157765628 | ||
|
|
8689037ceb | ||
|
|
03a8914986 | ||
|
|
26b9d6706d | ||
|
|
a21d4a9eb6 | ||
|
|
212d614ebd | ||
|
|
bcba3ccde0 | ||
|
|
b42ad76372 | ||
|
|
f95565771a | ||
|
|
3d6cbf5ac1 | ||
|
|
fc5d43e14b | ||
|
|
b3264748cd | ||
|
|
ede40f06d0 | ||
|
|
e69c675f82 | ||
|
|
17c1c90957 | ||
|
|
c6f2f71f6c | ||
|
|
d2c7c151bc | ||
|
|
4448eca787 | ||
|
|
0350a77dff | ||
|
|
4f98c599df | ||
|
|
103b2407d2 | ||
|
|
059da9be12 | ||
|
|
3cac3a997e | ||
|
|
3ffb001c73 | ||
|
|
2810a6f952 | ||
|
|
166362334b | ||
|
|
d3f9103ebf | ||
|
|
1c5507d4a5 | ||
|
|
5e3cd9f484 | ||
|
|
f27b884b6a | ||
|
|
769a9d8ea5 | ||
|
|
9499a7f0e0 | ||
|
|
ca38583f96 | ||
|
|
9557a0cfb5 | ||
|
|
c61e8bb7fc | ||
|
|
4fbcaa47f8 | ||
|
|
6f31fc5abb | ||
|
|
10ec0e35d0 | ||
|
|
29c4d253cf | ||
|
|
55c870d392 | ||
|
|
cda6ec066d | ||
|
|
c8b89e6847 | ||
|
|
b46a739008 | ||
|
|
af62394651 | ||
|
|
bc75a5cd97 | ||
|
|
7d8af3af08 | ||
|
|
ef8197b275 | ||
|
|
58d9ac7fdd | ||
|
|
86a893916d | ||
|
|
e7a6292fe9 | ||
|
|
81209b0cf8 | ||
|
|
77b8147f9b | ||
|
|
32abd7e14e | ||
|
|
8a582f0b08 | ||
|
|
01be6f7d43 | ||
|
|
9011700879 | ||
|
|
12cd4e5e5f | ||
|
|
10201bcadb | ||
|
|
3b4fcc0069 | ||
|
|
31a1ef74fb | ||
|
|
9be3a1475f | ||
|
|
7591f396fd | ||
|
|
517b84042f | ||
|
|
dbfae33074 | ||
|
|
ead34009c6 | ||
|
|
7a4a0f05d1 | ||
|
|
8f32b2d887 | ||
|
|
e6c9600b40 | ||
|
|
d5f2acb9ab | ||
|
|
3274e96355 | ||
|
|
78dfa286b0 | ||
|
|
f32624d131 | ||
|
|
59a417056c | ||
|
|
18f6704ed7 | ||
|
|
caf2f22e9f |
@@ -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:
|
||||||
|
files: build/test-results/**/*.xml
|
||||||
|
fail_on: nothing
|
||||||
|
ignore_runs: true
|
||||||
|
json_thousands_separator: .
|
||||||
|
time_unit: milliseconds
|
||||||
|
|
||||||
|
- name: Create Badge Color
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in
|
||||||
|
success)
|
||||||
|
echo "BADGE_COLOR=31c653" >> $GITHUB_ENV
|
||||||
|
;;
|
||||||
|
failure)
|
||||||
|
echo "BADGE_COLOR=800000" >> $GITHUB_ENV
|
||||||
|
;;
|
||||||
|
neutral)
|
||||||
|
echo "BADGE_COLOR=696969" >> $GITHUB_ENV
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
- name: Create Test Badge
|
||||||
|
uses: emibcn/badge-action@v1.2.4
|
||||||
|
with:
|
||||||
|
label: Tests
|
||||||
|
status: '${{ fromJSON( steps.test-results.outputs.json ).conclusion }}, Passed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_succ }}, Skipped: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_skip }}, Failed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_fail }}'
|
||||||
|
color: ${{ env.BADGE_COLOR }}
|
||||||
|
path: tests.svg
|
||||||
|
|
||||||
|
- name: Create Coverage Badge
|
||||||
|
id: jacoco
|
||||||
|
uses: cicirello/jacoco-badge-generator@v2
|
||||||
|
with:
|
||||||
|
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
|
||||||
|
badges-directory: null
|
||||||
|
intervals: 95 80 70 60 50 0
|
||||||
|
|
||||||
|
- name: Upload Test Badge
|
||||||
|
uses: exuanbo/actions-deploy-gist@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GIST_TOKEN }}
|
||||||
|
gist_id: 280257cd19cbe1dda3789bebd4ff65cf
|
||||||
|
file_path: tests.svg
|
||||||
|
|
||||||
|
- name: Upload Coverage Badge
|
||||||
|
uses: exuanbo/actions-deploy-gist@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GIST_TOKEN }}
|
||||||
|
gist_id: 280257cd19cbe1dda3789bebd4ff65cf
|
||||||
|
file_path: jacoco.svg
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
name: Unit Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Unit Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up JDK 11
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: 11
|
||||||
|
cache: gradle
|
||||||
|
|
||||||
|
- name: Make gradlew executable
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
- name: Build and Test
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: ./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true
|
||||||
|
|
||||||
|
- name: Publish Test Result
|
||||||
|
uses: EnricoMi/publish-unit-test-result-action@v2
|
||||||
|
id: test-results
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
files: build/test-results/**/*.xml
|
||||||
|
fail_on: nothing
|
||||||
|
ignore_runs: true
|
||||||
|
json_thousands_separator: .
|
||||||
|
time_unit: milliseconds
|
||||||
+14
-1
@@ -1,7 +1,6 @@
|
|||||||
# ---> Gradle
|
# ---> Gradle
|
||||||
.gradle
|
.gradle
|
||||||
/build/
|
/build/
|
||||||
gradle.properties
|
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
# Ignore Gradle GUI config
|
||||||
gradle-app.setting
|
gradle-app.setting
|
||||||
@@ -31,5 +30,19 @@ gradle-app.setting
|
|||||||
/src/main/java/speiger/src/collections/doubles/*
|
/src/main/java/speiger/src/collections/doubles/*
|
||||||
/src/main/java/speiger/src/collections/objects/*
|
/src/main/java/speiger/src/collections/objects/*
|
||||||
|
|
||||||
|
#Generated Tests
|
||||||
|
/src/test/java/speiger/src/testers/booleans/*
|
||||||
|
/src/test/java/speiger/src/testers/bytes/*
|
||||||
|
/src/test/java/speiger/src/testers/shorts/*
|
||||||
|
/src/test/java/speiger/src/testers/chars/*
|
||||||
|
/src/test/java/speiger/src/testers/ints/*
|
||||||
|
/src/test/java/speiger/src/testers/longs/*
|
||||||
|
/src/test/java/speiger/src/testers/floats/*
|
||||||
|
/src/test/java/speiger/src/testers/doubles/*
|
||||||
|
/src/test/java/speiger/src/testers/objects/*
|
||||||
|
/src/test/java/speiger/src/tests/*
|
||||||
|
|
||||||
#Cache result
|
#Cache result
|
||||||
/src/builder/resources/speiger/assets/collections/cache.bin
|
/src/builder/resources/speiger/assets/collections/cache.bin
|
||||||
|
/src/builder/resources/speiger/assets/testers/cache.bin
|
||||||
|
/src/builder/resources/speiger/assets/tests/cache.bin
|
||||||
|
|||||||
@@ -1,5 +1,101 @@
|
|||||||
# Changelog of versions
|
# Changelog of versions
|
||||||
|
|
||||||
|
### 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
|
||||||
|
- Added: addOrGet for sets.
|
||||||
|
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
||||||
|
- Added: CopyOnWriteArrayList and tests for it
|
||||||
|
- Added: Support up to Java17.
|
||||||
|
- Added: Build System now adds module-info if the Running JVM is 9 or higher
|
||||||
|
- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array.
|
||||||
|
- Added: A ConcurrentHashMap implementation.
|
||||||
|
- Fixed: containsValue in the HashMap wouldn't check the nullKey
|
||||||
|
- Removed: Deprecated functions from SortedMaps/Sets
|
||||||
|
|
||||||
|
### Version 0.5.3
|
||||||
|
- Added: OrderedMap/Set
|
||||||
|
- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set
|
||||||
|
- Added: subFrom to Maps which is the counterpart of the addTo method
|
||||||
|
- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable
|
||||||
|
- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections.
|
||||||
|
- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted.
|
||||||
|
|
||||||
|
### Version 0.5.2
|
||||||
|
- Fixed: Bugs with Queues starting with the wrong size
|
||||||
|
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
|
||||||
|
- Added: Benchmarks with java and FastUtil
|
||||||
|
|
||||||
|
### Version 0.5.1
|
||||||
|
- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable.
|
||||||
|
- Added: Another 150k Unit tests.
|
||||||
|
- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists)
|
||||||
|
- Fixed: Bugs with null values for primitive collections.
|
||||||
|
- Removed: ArraySet/Map subSet/subMap implementation was removed.
|
||||||
|
|
||||||
### Version 0.5.0
|
### Version 0.5.0
|
||||||
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||||
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
||||||
|
|||||||
@@ -1,208 +1,201 @@
|
|||||||
Apache License
|
Apache License
|
||||||
|
Version 2.0, December 2021
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
Version 2.0, January 2021
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION,
|
|
||||||
AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and distribution
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
as defined by Sections 1 through 9 of this document.
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
"Object" form shall mean any form resulting from mechanical
|
||||||
owner that is granting the License.
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
"Contribution" shall mean any work of authorship, including
|
||||||
that control, are controlled by, or are under common control with that entity.
|
the original version of the Work and any modifications or additions
|
||||||
For the purposes of this definition, "control" means (i) the power, direct
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
or indirect, to cause the direction or management of such entity, whether
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
of the outstanding shares, or (iii) beneficial ownership of such entity.
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
granted by this License.
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications, including
|
(b) You must cause any modified files to carry prominent notices
|
||||||
but not limited to software source code, documentation source, and configuration
|
stating that You changed the files; and
|
||||||
files.
|
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation
|
You may add Your own copyright statement to Your modifications and
|
||||||
or translation of a Source form, including but not limited to compiled object
|
may provide additional or different license terms and conditions
|
||||||
code, generated documentation, and conversions to other media types.
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form,
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
made available under the License, as indicated by a copyright notice that
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
is included in or attached to the work (an example is provided in the Appendix
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
below).
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object form,
|
END OF TERMS AND CONDITIONS
|
||||||
that is based on (or derived from) the Work and for which the editorial revisions,
|
|
||||||
annotations, elaborations, or other modifications represent, as a whole, an
|
|
||||||
original work of authorship. For the purposes of this License, Derivative
|
|
||||||
Works shall not include works that remain separable from, or merely link (or
|
|
||||||
bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including the original version
|
Copyright 2021 Speiger
|
||||||
of the Work and any modifications or additions to that Work or Derivative
|
|
||||||
Works thereof, that is intentionally submitted to Licensor for inclusion in
|
|
||||||
the Work by the copyright owner or by an individual or Legal Entity authorized
|
|
||||||
to submit on behalf of the copyright owner. For the purposes of this definition,
|
|
||||||
"submitted" means any form of electronic, verbal, or written communication
|
|
||||||
sent to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems, and
|
|
||||||
issue tracking systems that are managed by, or on behalf of, the Licensor
|
|
||||||
for the purpose of discussing and improving the Work, but excluding communication
|
|
||||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
||||||
owner as "Not a Contribution."
|
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
Unless required by applicable law or agreed to in writing, software
|
||||||
of whom a Contribution has been received by Licensor and subsequently incorporated
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
within the Work.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of this
|
limitations under the License.
|
||||||
License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
||||||
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
|
|
||||||
Derivative Works of, publicly display, publicly perform, sublicense, and distribute
|
|
||||||
the Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
||||||
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
||||||
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
||||||
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
||||||
transfer the Work, where such license applies only to those patent claims
|
|
||||||
licensable by such Contributor that are necessarily infringed by their Contribution(s)
|
|
||||||
alone or by combination of their Contribution(s) with the Work to which such
|
|
||||||
Contribution(s) was submitted. If You institute patent litigation against
|
|
||||||
any entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
|
||||||
that the Work or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses granted to You
|
|
||||||
under this License for that Work shall terminate as of the date such litigation
|
|
||||||
is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
||||||
Derivative Works thereof in any medium, with or without modifications, and
|
|
||||||
in Source or Object form, provided that You meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or Derivative Works a copy
|
|
||||||
of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices stating that
|
|
||||||
You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works that You distribute,
|
|
||||||
all copyright, patent, trademark, and attribution notices from the Source
|
|
||||||
form of the Work, excluding those notices that do not pertain to any part
|
|
||||||
of the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
||||||
then any Derivative Works that You distribute must include a readable copy
|
|
||||||
of the attribution notices contained within such NOTICE file, excluding those
|
|
||||||
notices that do not pertain to any part of the Derivative Works, in at least
|
|
||||||
one of the following places: within a NOTICE text file distributed as part
|
|
||||||
of the Derivative Works; within the Source form or documentation, if provided
|
|
||||||
along with the Derivative Works; or, within a display generated by the Derivative
|
|
||||||
Works, if and wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and do not modify the
|
|
||||||
License. You may add Your own attribution notices within Derivative Works
|
|
||||||
that You distribute, alongside or as an addendum to the NOTICE text from the
|
|
||||||
Work, provided that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and may provide
|
|
||||||
additional or different license terms and conditions for use, reproduction,
|
|
||||||
or distribution of Your modifications, or for any such Derivative Works as
|
|
||||||
a whole, provided Your use, reproduction, and distribution of the Work otherwise
|
|
||||||
complies with the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
||||||
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
||||||
Licensor shall be under the terms and conditions of this License, without
|
|
||||||
any additional terms or conditions. Notwithstanding the above, nothing herein
|
|
||||||
shall supersede or modify the terms of any separate license agreement you
|
|
||||||
may have executed with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade names,
|
|
||||||
trademarks, service marks, or product names of the Licensor, except as required
|
|
||||||
for reasonable and customary use in describing the origin of the Work and
|
|
||||||
reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
|
|
||||||
in writing, Licensor provides the Work (and each Contributor provides its
|
|
||||||
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
KIND, either express or implied, including, without limitation, any warranties
|
|
||||||
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness
|
|
||||||
of using or redistributing the Work and assume any risks associated with Your
|
|
||||||
exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory, whether
|
|
||||||
in tort (including negligence), contract, or otherwise, unless required by
|
|
||||||
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
||||||
in writing, shall any Contributor be liable to You for damages, including
|
|
||||||
any direct, indirect, special, incidental, or consequential damages of any
|
|
||||||
character arising as a result of this License or out of the use or inability
|
|
||||||
to use the Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all other commercial
|
|
||||||
damages or losses), even if such Contributor has been advised of the possibility
|
|
||||||
of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing the Work
|
|
||||||
or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
||||||
acceptance of support, warranty, indemnity, or other liability obligations
|
|
||||||
and/or rights consistent with this License. However, in accepting such obligations,
|
|
||||||
You may act only on Your own behalf and on Your sole responsibility, not on
|
|
||||||
behalf of any other Contributor, and only if You agree to indemnify, defend,
|
|
||||||
and hold each Contributor harmless for any liability incurred by, or claims
|
|
||||||
asserted against, such Contributor by reason of your accepting any such warranty
|
|
||||||
or additional liability. END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following boilerplate
|
|
||||||
notice, with the fields enclosed by brackets "[]" replaced with your own identifying
|
|
||||||
information. (Don't include the brackets!) The text should be enclosed in
|
|
||||||
the appropriate comment syntax for the file format. We also recommend that
|
|
||||||
a file or class name and description of purpose be included on the same "printed
|
|
||||||
page" as the copyright notice for easier identification within third-party
|
|
||||||
archives.
|
|
||||||
|
|
||||||
Copyright 2021 Speiger
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
|
|
||||||
limitations under the License.
|
|
||||||
|
|||||||
@@ -1,115 +1,59 @@
|
|||||||
|

|
||||||
|
[](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
|
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||||
- HashSet/Map (Linked & HashControl)
|
- HashSets/Maps (Linked & HashControl)
|
||||||
- TreeSet/Map (RB & AVL)
|
- TreeSets/Maps (RB & AVL)
|
||||||
- EnumMap
|
- EnumMaps
|
||||||
- Immutable Maps/Lists/Sets
|
- Immutable Maps/Lists/Sets
|
||||||
- Priority Queue
|
- ConcurrentHashMaps
|
||||||
|
- 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
|
||||||
|
|
||||||
## Current Level of Stability
|
|
||||||
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
|
|
||||||
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 16000 test covering Maps/Sets/Lists.
|
|
||||||
These tests cover Javas Collection API completely and ensuring a Stable implementation.
|
|
||||||
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
|
|
||||||
These will be expanded on as time goes on.
|
|
||||||
|
|
||||||
One know aspect of Instability is SubSets and SubMaps. They require full rewrites to be fully stable.
|
|
||||||
So it is not advised to use them until these issues are addressed.
|
|
||||||
PriorityQueues are tested separately and ensure basic functionality though GuavaTests are planned.
|
|
||||||
They just require a custom test implementation.
|
|
||||||
|
|
||||||
As a summary: Stability is good/excellent, unless you need SubSets/SubMaps
|
|
||||||
|
|
||||||
## Specialized Functions
|
|
||||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
|
||||||
To highlight things that may be wanted.
|
|
||||||
- Iterable:
|
|
||||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
|
||||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
|
||||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
|
||||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
|
||||||
- count: counts all valid elements in a collection.
|
|
||||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
|
||||||
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
|
|
||||||
- pour: a function that allows to collect all elements within the Collection
|
|
||||||
- Collection:
|
|
||||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
|
||||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
|
||||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
|
||||||
(subCollections not supported for obvious reasons)
|
|
||||||
- toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference
|
|
||||||
- List:
|
|
||||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
|
||||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
|
||||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
|
||||||
- addIfAbsent/Present: adds a element only if absent/present in the list
|
|
||||||
- swapRemove: deletes a desired element and inserts the last element in its place instead of leftshifting elements.
|
|
||||||
- SortedSet:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
|
||||||
- pollFirst/Last: Allows to poll the first/last element of the set.
|
|
||||||
- Map:
|
|
||||||
- putAll: putAll but in Array form.
|
|
||||||
- putAllIfAbsent: Puts only the elements that are absent.
|
|
||||||
- addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
|
|
||||||
- addToAll: Same as addTo but bulkVersion.
|
|
||||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
|
||||||
- mergeAll: BulkVersion of Merge function.
|
|
||||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
|
||||||
- Sorted Map:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
|
||||||
- getAndMoveToFirst/Last: gets the element and moves it to the first/last position. Replicating a Optional LinkedHashMap feature.
|
|
||||||
- pollFirst/LastKey: Allows to poll the first/last element.
|
|
||||||
- first/LastValue: Allows to get the first/last value from the Map.
|
|
||||||
|
|
||||||
|
|
||||||
# Notes about Versions
|
# Notes about Versions
|
||||||
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||||
Any breaking changes will be Documented (once 1.0 is released)
|
|
||||||
|
|
||||||
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.5.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.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) |
|
but if you want to just browse around in it.
|
||||||
| 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) |
|
Check out the [Debug Branch](https://github.com/Speiger/Primitive-Collections/tree/debug/src/main/java/speiger/src/collections), which has the entire up to date code.
|
||||||
| 0.4.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.
|
||||||
@@ -129,10 +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)
|
|
||||||
- SubMaps/Set implementation isn't perfect right now. This will be addressed slowly due to rewrites required.
|
|
||||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
|
||||||
+198
-15
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
id "jacoco"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
@@ -8,7 +9,7 @@ tasks.withType(JavaCompile) {
|
|||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -18,9 +19,11 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.5.0';
|
version = '0.7.0';
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||||
|
|
||||||
|
System.out.println("Java Version: "+compileJava.sourceCompatibility)
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
options.tags = [ "implSpec", "note" ]
|
options.tags = [ "implSpec", "note" ]
|
||||||
@@ -42,8 +45,7 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
builderCompile 'de.speiger:Simple-Code-Generator:1.0.5'
|
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4'
|
||||||
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5'
|
|
||||||
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'
|
||||||
|
|
||||||
@@ -56,12 +58,28 @@ task generateSource(type: JavaExec) {
|
|||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task generateGithubSource(type: JavaExec) {
|
||||||
|
group = 'internal'
|
||||||
|
description = 'Builds the sourcecode for Github Actions'
|
||||||
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
|
args = ['silent']
|
||||||
|
}
|
||||||
|
|
||||||
task forceGenerateSource(type: JavaExec) {
|
task forceGenerateSource(type: JavaExec) {
|
||||||
group = 'internal'
|
group = 'internal'
|
||||||
description = 'Builds the sourcecode forceful'
|
description = 'Builds the sourcecode forceful'
|
||||||
classpath = sourceSets.builder.runtimeClasspath
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
args = ['true']
|
args = ['force']
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateTestSource(type: JavaExec) {
|
||||||
|
group = 'internal'
|
||||||
|
description = 'Builds the sourcecode for the Tests'
|
||||||
|
classpath = sourceSets.builder.runtimeClasspath
|
||||||
|
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
|
||||||
|
args = ['tests', 'silent']
|
||||||
}
|
}
|
||||||
|
|
||||||
task javadocJar(type: Jar) {
|
task javadocJar(type: Jar) {
|
||||||
@@ -74,6 +92,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()
|
||||||
@@ -83,23 +103,171 @@ artifacts {
|
|||||||
archives srcJar
|
archives srcJar
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
task testBooleans(type: Test) {
|
||||||
|
group 'tests'
|
||||||
|
description 'Tests all Boolean Collections'
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
includeTestsMatching "speiger.src.tests.booleans.**.*"
|
||||||
|
}
|
||||||
useJUnit()
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadArchives {
|
task testBytes(type: Test) {
|
||||||
repositories.mavenDeployer {
|
group 'tests'
|
||||||
repository(url: 'https://maven.speiger.com/repository/main') {
|
description 'Tests all Byte Collections'
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
includeTestsMatching "speiger.src.tests.bytes.**.*"
|
||||||
}
|
}
|
||||||
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
useJUnit()
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
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 {
|
||||||
|
filter {
|
||||||
|
excludeTestsMatching "speiger.src.testers.**.*"
|
||||||
|
excludeTestsMatching "speiger.src.tests.**.*"
|
||||||
|
excludeTestsMatching "tests.**.*"
|
||||||
|
}
|
||||||
|
useJUnit()
|
||||||
|
ignoreFailures = true
|
||||||
|
maxHeapSize = "1024m"
|
||||||
|
}
|
||||||
|
|
||||||
|
jacocoTestReport {
|
||||||
|
executionData fileTree(project.buildDir.absolutePath).include("jacoco/*.exec")
|
||||||
|
reports {
|
||||||
|
xml.enabled true
|
||||||
|
html.enabled = true
|
||||||
|
csv.enabled true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
Properties props = new Properties()
|
||||||
|
if(file("$buildDir/credentials.properties").exists()) {
|
||||||
|
props.load(new FileInputStream("$buildDir/credentials.properties"))
|
||||||
|
}
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
pom {
|
pom {
|
||||||
|
name = 'Primitive Collections'
|
||||||
|
description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||||
version = project.version
|
version = project.version
|
||||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||||
groupId = 'de.speiger'
|
groupId = 'de.speiger'
|
||||||
project {
|
from components.java
|
||||||
|
artifact tasks.srcJar
|
||||||
|
artifact tasks.javadocJar
|
||||||
licenses {
|
licenses {
|
||||||
license {
|
license {
|
||||||
name = 'The Apache License, Version 2.0'
|
name = 'The Apache License, Version 2.0'
|
||||||
@@ -110,9 +278,24 @@ uploadArchives {
|
|||||||
developer {
|
developer {
|
||||||
id = 'speiger'
|
id = 'speiger'
|
||||||
name = 'Speiger'
|
name = 'Speiger'
|
||||||
email = 'speiger@gmx.net'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scm {
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||||
|
}
|
||||||
|
issueManagement {
|
||||||
|
system = 'github'
|
||||||
|
url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main"
|
||||||
|
credentials(PasswordCredentials) {
|
||||||
|
username props.mavenUser
|
||||||
|
password props.mavenPassword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+402
@@ -0,0 +1,402 @@
|
|||||||
|
## Quality Of Life Features
|
||||||
|
New Specialized functions/classes that were added to increase performance and/or reduce allocations and/or for Quality of life.
|
||||||
|
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
|
||||||
|
Functions that increase performance or are quality of life in their nature.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Iterable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
## Functional Functions
|
||||||
|
|
||||||
|
Java adds themselves a lot of functional functions like,
|
||||||
|
- Stream:
|
||||||
|
- Map/FlatMap
|
||||||
|
- Filter/Distinct/Limit/Sorted
|
||||||
|
- Count/FindFirst/Collect
|
||||||
|
- Peek/ForEach/Reduce
|
||||||
|
- anyMatch/allMatch/NoneMatch
|
||||||
|
|
||||||
|
that allows to process a collection in a functional way.
|
||||||
|
But these require streams which have a lot of Overhead in their nature.
|
||||||
|
|
||||||
|
Luckly Primitive Collections adds replacement functions that provide the same functionality but with minimal overhead.
|
||||||
|
Here are some examples:
|
||||||
|
```java
|
||||||
|
public ObjectIterable<Path> toPath(ObjectIterable<String> iterable) {
|
||||||
|
return iterable.map(Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Path> toPath(Iterable<String> iterable) {
|
||||||
|
return ObjectIterables.map(iterable, Paths::get).filter(Files::exist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(IntIterable iterable) {
|
||||||
|
return iterable.reduce(Integer::sum);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## AsyncAPI</summary>
|
||||||
|
|
||||||
|
The AsyncAPI is a Feature that simplifies the processing of Collections on a separate thread.
|
||||||
|
It uses the same concept as Javas Stream API but uses the light weight Functions from Primitive Collections to achieve the same thing.
|
||||||
|
Unlike Javas StreamAPI the AsyncAPI is always singleThreaded and more like Javas CompletableFuture, which you can await or let run Asynchronous.
|
||||||
|
|
||||||
|
The Goal is it to simplify the processing of Collections asynchronous.
|
||||||
|
Especially on tasks which don't have to be finished instantly but can be processed on the side.
|
||||||
|
|
||||||
|
Here is a example of how the API works.
|
||||||
|
```java
|
||||||
|
public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||||
|
potentialFiles.asAsync()
|
||||||
|
.map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
|
||||||
|
.forEach(Files::delete) //Creates the action (Required)
|
||||||
|
.callback(T -> {}} //Callback on completion, still offthread (Optional)
|
||||||
|
.execute() //Starts the task. (Required)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>Collection</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These are functions specific to the Collections interface, stuff that everyone wished it was present to be in the first place.
|
||||||
|
|
||||||
|
## AddAll (Array)
|
||||||
|
Adding Elements to a Collection usually requires either a for loop or a Arrays.wrap().
|
||||||
|
This isn't an issue with Primitive Collections.
|
||||||
|
```java
|
||||||
|
public void addMonths(ObjectCollection<String> months) {
|
||||||
|
months.addAll("January", "February", "March", "April", "May", "June", "July", "August", "September, "October", November", "December");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addElements(ObjectCollection<String> result, String[] elements) {
|
||||||
|
result.addAll(elements, 0, 5); //elements, offset, length
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## containsAny
|
||||||
|
Everyone hates comparing if 2 collections have part of each other included.
|
||||||
|
The solution usually requires for loops and keeping track if things were found or not.
|
||||||
|
And every Java Developer had this issue at least once and wished for a clean solution.
|
||||||
|
```java
|
||||||
|
public boolean hasMonths(ObjectCollection<Month> target, Collection<Month> toFind) {
|
||||||
|
return target.containsAny(toFind);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Copy
|
||||||
|
Collections get copied every now and then. There is only 2 ways that this happens.
|
||||||
|
Javas Clone API or using Constructor that supports collections.
|
||||||
|
Javas Clone API is kinda in a Zombie state, where it is supported or not. Its not really clear if you should use it or not.
|
||||||
|
The Clone CloneNotSupportedException isn't helping either, causing more janky code.
|
||||||
|
While a Constructor can only support so much and testing for every case isn't really viable.
|
||||||
|
|
||||||
|
So the decision was made to straight out not support clone and instead add a copy function which doesn't use a checked exception.
|
||||||
|
It works exactly like the clone function. In a sense where it creates a shallow copy. (SubCollections do not work for obvious reasons)
|
||||||
|
```java
|
||||||
|
public IntCollection copy(IntCollection original) {
|
||||||
|
return original.copy();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Primitive Streams
|
||||||
|
Since Javas Stream API is still really useful, even at its shortcomings, Primitive Collections provides easy access to it.
|
||||||
|
Generic Streams and the closest Primitive Stream will be provided. So a FloatCollection goes to a DoubleStream.
|
||||||
|
```java
|
||||||
|
public IntStream createStream(IntCollection source) {
|
||||||
|
return source.primitiveStream();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## RemoveAll/RetainAll with listener
|
||||||
|
Ever wanted use removeAll or retainAll and wanted to know what elements actually got deleted?
|
||||||
|
The usual solution is to create a copy and then apply it to the original and cross reference them.
|
||||||
|
Which leads to really messy code and just hasn't a clean solution.
|
||||||
|
Luckly Primitive Collections got you covered.
|
||||||
|
```java
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toRemove) {
|
||||||
|
files.removeAll(toRemove, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toKeep) {
|
||||||
|
files.retainFiles(toKeep, T -> System.out.println(T));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## ToArray
|
||||||
|
Primitive Collections supports primitive/generic toArray functions for its Primitive Collections.
|
||||||
|
On top of that the Object side gets a Java9 function ported back to java8, which uses a functional Interface to create the backing array.
|
||||||
|
```java
|
||||||
|
public Integer[] toArray(IntCollection c) {
|
||||||
|
return c.toArray(new Integer[c.size]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] toArray(IntCollection c) {
|
||||||
|
return c.toIntArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] toArray(ObjectCollection<String> c) {
|
||||||
|
return c.toArray(String::new);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>List</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are List specific functions, a couple of these are from FastUtil.
|
||||||
|
|
||||||
|
## add/get/remove/extractElements
|
||||||
|
These functions really useful helper functions. 3 of which are copied from FastUtil. (extract is from Primitive Collections)
|
||||||
|
They are basically array forms of addAll, getAll, removeRange and removeAndGetRange. This is the simplest way to describe it.
|
||||||
|
|
||||||
|
Here some example:
|
||||||
|
```java
|
||||||
|
public void addAll(DoubleList list) {
|
||||||
|
list.addElements(0D, 12.2D, 3.5D, 4.2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getAll(DoubleList list, int amount) {
|
||||||
|
double[] result = new double[amount];
|
||||||
|
list.getElements(0, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRange(FloatList list) {
|
||||||
|
list.removeElements(5, 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] extractRange(FloatList list) {
|
||||||
|
return list.extractElements(5, 14); //Returns the removed elements
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addIfPresent/addIfAbsent
|
||||||
|
These two functions are simple helper functions that check internally if a element is present or absent before adding them to the List.
|
||||||
|
Removing the need for a contains or indexOf check every time you want to add a element.
|
||||||
|
While it is of course better to use a set, there is cases where this is still useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addElements(IntList list, int... numbersToAdd) {
|
||||||
|
for(int e : numbersToAdd) {
|
||||||
|
list.addIfAbsent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addExisting(ObjectList<String> list, String... textToAdd) {
|
||||||
|
for(String s : textToAdd) {
|
||||||
|
list.addIfPresent(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## SwapRemove
|
||||||
|
Lists when removing a Element shift usually the backing array to the left based to shrink the elements.
|
||||||
|
While that isn't computational expensive with LinkedLists, it is with ArrayLists.
|
||||||
|
Here comes swapRemove into play, which just removes the desired elements and instead of shifting left puts the last element in its place.
|
||||||
|
This reduces the data copying required down to 1 element instead of an array.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public int remove(IntList elements, int indexToRemove) {
|
||||||
|
return elements.swapRemove(indexToRemove);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unstable Sort (From FastUtil)
|
||||||
|
Unstable Sort uses a Faster but not as stable sorting algorithm to sort the Collection.
|
||||||
|
Stable doesn't mean crashing, but more like that the result isn't exactly perfectly sorted.
|
||||||
|
```java
|
||||||
|
public void sort(List<Month> list, Comparator<Month> sorter) {
|
||||||
|
list.unstableSort(sorter);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Map</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
These functions are based on the Map interface. Useful functions you really would want.
|
||||||
|
|
||||||
|
## addTo/subFrom
|
||||||
|
addTo (from FastUtil) and subFrom are mathematically functions that either add or subtract from the value of a given key.
|
||||||
|
And if the key isn't present or would result in the default value it will either add or remove the entry from the Map. Given the circumstance.
|
||||||
|
This is a really useful function and I wish FastUtil made it accessible by default but sadly it isn't.
|
||||||
|
To simplify the explanation:
|
||||||
|
- addTo if no element is present puts in the desired number, otherwise it sums up the two values.
|
||||||
|
- subFrom if a element is present subtracts from it, if the element reaches the default value it removes the element from the map. If not present it will be ignored.
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Month key, double averageTrainsRepaired) {
|
||||||
|
map.addTo(key, averageTrainsRepaired);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subFrom(Long2IntMap map, long key, double amount) {
|
||||||
|
map.subFrom(key, amount);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## addToAll
|
||||||
|
Simple bulk version of the addTo function since sometimes you want to merge 2 maps for summing.
|
||||||
|
Especially if your work is multi-threaded this can become useful.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public void addTo(Object2DoubleMap<Month> map, Object2DoubleMap<Month> trainsRepaired) {
|
||||||
|
map.addToAll(trainsRepaired);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## mergeAll
|
||||||
|
This is a simple bulk version of merge since merging 2 maps is more frequent then people might think and leads to cleaner code too.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ByteMap result, Long2ByteMap toMerge) {
|
||||||
|
result.mergeAll(toMerge);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAll (Array)
|
||||||
|
This allows to put keys and values as arrays instead of requiring a WrapperMap to insert the elements.
|
||||||
|
Not as useful as the Collections.addAll variant but still really useful.
|
||||||
|
```java
|
||||||
|
public void putAll(Int2DoubleMap map, int[] keys, double[] values) {
|
||||||
|
map.put(keys, values, 2, 15);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## putAllIfAbsent
|
||||||
|
putAll has this usual quirk where if a element is present it will replace the value, and sometimes this is not wanted.
|
||||||
|
While putIfAbsent exists it has no real mass form and makes iterative solutions really uneasy to use.
|
||||||
|
Here comes the helper function that gets rid of that problem.
|
||||||
|
```java
|
||||||
|
public void merge(Long2ObjectMap<String> regionFiles, Long2ObjectMap<String> toAdd) {
|
||||||
|
regionFiles.putAllIfAbsent(toAdd);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## removeOrDefault
|
||||||
|
getOrDefault is a really useful function that find use cases all the time.
|
||||||
|
Sadly by default there is no variant of removeOrDefault, while it has less cases still could be used every now and then.
|
||||||
|
This function basically tries to remove a element, if it is not present it will just return your desired default.
|
||||||
|
```java
|
||||||
|
public Path removeCache(Long2ObjectMap<Path> caches, long key) {
|
||||||
|
return caches.removeOrDefault(key, Paths.get("nuclearFun"));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## supplyIfAbsent
|
||||||
|
This one is one of my favorites. computeIfAbsent is a really useful function.
|
||||||
|
But in 90% of the cases I use it the value is a collection.
|
||||||
|
This becomes really annoying since methodReferences are faster/cleaner then Lambdas in my opinion.
|
||||||
|
supplyIfAbsent is basically computeIfAbsent but without a key, perfect for the default constructor of a collection.
|
||||||
|
This is the whole reason it exists.
|
||||||
|
```java
|
||||||
|
public void example(Int2ObjectMap<List<String>> map, Int2ObjectMap<String> toAdd) {
|
||||||
|
for(Entry<String> entry : toAdd.entrySet()) {
|
||||||
|
map.supplyIfAbsent(entry.getKey(), ObjectArrayList::new).add(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
# Interfaces
|
||||||
|
|
||||||
|
Interfaces that provide essential or quality of life features.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>ITrimmable</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The ITrimmable is Accessor interface that allows you to access a couple helper functions to control the size of your collections.
|
||||||
|
This was created for the constant casting requirement to implementations just to shrink collections which get annoying over time.
|
||||||
|
|
||||||
|
## trim
|
||||||
|
This function basically trims down the backing implementation to use as little memory as required to store the elements in the collection.
|
||||||
|
Optionally a desired minimum size can be provided as of how low it should go at worst.
|
||||||
|
|
||||||
|
## clearAndTrim
|
||||||
|
when you want to reset a Collection completely you have 2 options. Clear it and then call trim, or recreate the collection.
|
||||||
|
clearAndTrim solves this problem by clearing the collection and trimming it in one go, reducing overhead to achieve such a thing.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>IArray</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
IArray is a Accessor interface that provides more access to collections by providing tools to grow your collection as needed.
|
||||||
|
While putAll/addAll try to ensure that you have enough room for your elements, this is not really a solution for all cases.
|
||||||
|
Sometimes you need to ensure the Collection is pre-initialized.
|
||||||
|
IArray grants you that control.
|
||||||
|
|
||||||
|
There is also a type specific that provides you access to the backing array implementation of Lists for faster Iteration but that is a really specific case.
|
||||||
|
|
||||||
|
## ensureCapacity
|
||||||
|
Ensures that your collection has enough storage for the elements you want to insert.
|
||||||
|
|
||||||
|
## elements (ITypeSpecificArray)
|
||||||
|
Allows you access to the backing array of a List which is for people who know what they are doing.
|
||||||
|
There is a lambda version of this function too which makes sure for synchronizedLists that you are the only one accessing the array.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedMap</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedMap is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedMap because the Set wasn't sorted.
|
||||||
|
So OrderedMap was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## getAndMoveToFirst/getAndMoveToLast
|
||||||
|
Returns a desired element and removing it to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## putAndMoveToFirst/putAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## firstKey/lastKey (Optional poll)
|
||||||
|
Provides access to the current first/last key of the Map.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
## firstValue/lastValue
|
||||||
|
Provides access to the current first/last value of the Map.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>OrderedSet</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
The OrderedSet is a real edge case interface that was born for a need.
|
||||||
|
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||||
|
They didn't fit into something like a SortedSet because the Set wasn't sorted.
|
||||||
|
So OrderedSet was born, which isn't random but ordered in a specific way that can be changed.
|
||||||
|
|
||||||
|
## addAndMoveToFirst/addAndMoveToLast
|
||||||
|
Adds the desired element and moves it to first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
|
||||||
|
## moveToFirst/moveToLast
|
||||||
|
Moves the element if present to the first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||||
|
Returns true if the element was actually moved.
|
||||||
|
|
||||||
|
## first/last (Optional poll)
|
||||||
|
Provides access to the current first/last element of the set.
|
||||||
|
Optionally can be polled if desired.
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx3G
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
jdk:
|
||||||
|
- openjdk9
|
||||||
|
install:
|
||||||
|
- chmod +x ./gradlew
|
||||||
|
- ./gradlew build publishToMavenLocal
|
||||||
|
|
||||||
@@ -3,15 +3,15 @@ package speiger.src.builder;
|
|||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public enum ClassType
|
public enum ClassType
|
||||||
{
|
{
|
||||||
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false"),
|
BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false", "false"),
|
||||||
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0"),
|
BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0", "(byte)-1"),
|
||||||
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0"),
|
SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0", "(short)-1"),
|
||||||
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0"),
|
CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0", "(char)-1"),
|
||||||
INT("int", "Integer", "Int", "ints", "INT", "0"),
|
INT("int", "Integer", "Int", "ints", "INT", "0", "-1"),
|
||||||
LONG("long", "Long", "Long", "longs", "LONG", "0L"),
|
LONG("long", "Long", "Long", "longs", "LONG", "0L", "-1L"),
|
||||||
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F"),
|
FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F", "-1F"),
|
||||||
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D"),
|
DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D", "-1D"),
|
||||||
OBJECT("T", "T", "Object", "objects", "OBJECT", "null");
|
OBJECT("T", "T", "Object", "objects", "OBJECT", "null", "null");
|
||||||
|
|
||||||
String keyType;
|
String keyType;
|
||||||
String classType;
|
String classType;
|
||||||
@@ -19,8 +19,9 @@ public enum ClassType
|
|||||||
String pathType;
|
String pathType;
|
||||||
String capType;
|
String capType;
|
||||||
String emptyValue;
|
String emptyValue;
|
||||||
|
String invalidValue;
|
||||||
|
|
||||||
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue)
|
private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue, String invalidValue)
|
||||||
{
|
{
|
||||||
this.keyType = keyType;
|
this.keyType = keyType;
|
||||||
this.classType = classType;
|
this.classType = classType;
|
||||||
@@ -28,6 +29,7 @@ public enum ClassType
|
|||||||
this.pathType = pathType;
|
this.pathType = pathType;
|
||||||
this.capType = capType;
|
this.capType = capType;
|
||||||
this.emptyValue = emptyValue;
|
this.emptyValue = emptyValue;
|
||||||
|
this.invalidValue = invalidValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyType()
|
public String getKeyType()
|
||||||
@@ -90,6 +92,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;
|
||||||
|
|||||||
@@ -35,21 +35,43 @@ public class GlobalVariables
|
|||||||
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
addSimpleMapper("CLASS_TYPE", type.getClassType());
|
||||||
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType());
|
||||||
addSimpleMapper("KEY_TYPE", type.getKeyType());
|
addSimpleMapper("KEY_TYPE", type.getKeyType());
|
||||||
|
addSimpleMapper("KEY_OBJECT_TYPE", type.isObject() ? "Object" : type.getKeyType());
|
||||||
|
addSimpleMapper("KEY_STRING_TYPE", type.isObject() ? "String" : type.getKeyType());
|
||||||
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
|
addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType());
|
||||||
|
addSimpleMapper("CLASS_OBJECT_TYPE", type.getClassType());
|
||||||
|
addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType());
|
||||||
|
addSimpleMapper("CLASS_STRING_TYPE", type.isObject() ? "String" : type.getClassType());
|
||||||
|
addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType());
|
||||||
addSimpleMapper("VALUE_TYPE", valueType.getValueType());
|
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("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType());
|
||||||
|
addSimpleMapper("KEY_JAVA_TYPE", type.getCustomJDKType().getKeyType());
|
||||||
|
addSimpleMapper("VALUE_JAVA_TYPE", type.getCustomJDKType().getKeyType());
|
||||||
|
|
||||||
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
|
addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue());
|
||||||
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue());
|
||||||
|
|
||||||
|
addSimpleMapper("INVALID_KEY_VALUE", type.getInvalidValue());
|
||||||
|
addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue());
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_STRING_GENERIC_TYPE", type.isObject() ? "<String>" : "");
|
||||||
|
addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "<String>" : "");
|
||||||
|
addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<String, String>" : "<String>") : (valueType.isObject() ? "<String>" : ""));
|
||||||
|
|
||||||
|
|
||||||
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : "");
|
||||||
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
|
addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", type.isObject() ? "<"+type.getClassType()+">" : "");
|
||||||
|
|
||||||
|
|
||||||
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : "");
|
||||||
addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+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", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+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(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""));
|
||||||
|
addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+type.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces();
|
||||||
|
|
||||||
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "<?>" : "");
|
||||||
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<?, ?>" : "<?>") : valueType.isObject() ? "<?>" : "");
|
||||||
@@ -59,6 +81,10 @@ public class GlobalVariables
|
|||||||
addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "<? super "+valueType.getValueType()+">" : "");
|
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_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? super "+type.getKeyType()+", ? super "+valueType.getValueType()+">" : "<? super "+type.getKeyType()+">") : (valueType.isObject() ? "<? super "+valueType.getValueType()+">" : ""));
|
||||||
|
|
||||||
|
addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", type.isObject() ? "<? extends "+type.getKeyType()+">" : "");
|
||||||
|
addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "<? extends "+valueType.getValueType()+">" : "");
|
||||||
|
addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<? extends "+type.getKeyType()+", ? extends "+valueType.getValueType()+">" : "<? extends "+type.getKeyType()+">") : (valueType.isObject() ? "<? extends "+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_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()+">>" : ""));
|
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()+">>" : ""));
|
||||||
|
|
||||||
@@ -83,6 +109,7 @@ public class GlobalVariables
|
|||||||
addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
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(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable<T>>" : "");
|
||||||
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
|
addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : "");
|
||||||
|
addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : "");
|
||||||
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
|
addSimpleMapper("BRACES", type.isObject() ? "<>" : "");
|
||||||
if(type.needsCustomJDKType())
|
if(type.needsCustomJDKType())
|
||||||
{
|
{
|
||||||
@@ -120,6 +147,7 @@ public class GlobalVariables
|
|||||||
addInjectMapper(fix+"_EQUALS_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_NOT", type.getEquals(true)).removeBraces();
|
||||||
addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).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("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();
|
addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces();
|
||||||
@@ -135,7 +163,8 @@ public class GlobalVariables
|
|||||||
addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY");
|
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_"+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_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();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GlobalVariables createPreFunctions()
|
public GlobalVariables createPreFunctions()
|
||||||
@@ -158,6 +187,8 @@ public class GlobalVariables
|
|||||||
|
|
||||||
//Final Classes
|
//Final Classes
|
||||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||||
|
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
|
||||||
|
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
|
||||||
addClassMapper("LINKED_LIST", "LinkedList");
|
addClassMapper("LINKED_LIST", "LinkedList");
|
||||||
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
||||||
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
addClassMapper("ARRAY_FIFO_QUEUE", "ArrayFIFOQueue");
|
||||||
@@ -172,6 +203,7 @@ public class GlobalVariables
|
|||||||
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
||||||
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
||||||
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
||||||
|
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
|
||||||
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
||||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
||||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
||||||
@@ -183,6 +215,42 @@ public class GlobalVariables
|
|||||||
addClassMapper("RB_TREE_SET", "RBTreeSet");
|
addClassMapper("RB_TREE_SET", "RBTreeSet");
|
||||||
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
|
addClassMapper("AVL_TREE_SET", "AVLTreeSet");
|
||||||
addClassMapper("ARRAY_SET", "ArraySet");
|
addClassMapper("ARRAY_SET", "ArraySet");
|
||||||
|
addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2");
|
||||||
|
|
||||||
|
//Final UnitTest Classes
|
||||||
|
addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection");
|
||||||
|
addAbstractMapper("MINIMAL_SET", "Minimal%sSet");
|
||||||
|
addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester");
|
||||||
|
addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester");
|
||||||
|
addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester");
|
||||||
|
addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester");
|
||||||
|
addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester");
|
||||||
|
addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester");
|
||||||
|
addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester");
|
||||||
|
addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2");
|
||||||
|
addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester");
|
||||||
|
addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester");
|
||||||
|
addClassMapper("ITERATOR_TESTER", "IteratorTester");
|
||||||
|
addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder");
|
||||||
|
addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder");
|
||||||
|
addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder");
|
||||||
|
addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder");
|
||||||
|
addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder");
|
||||||
|
addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder");
|
||||||
|
addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder");
|
||||||
|
addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder");
|
||||||
|
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");
|
||||||
|
addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2");
|
||||||
|
addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests");
|
||||||
|
addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator");
|
||||||
|
addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator");
|
||||||
|
addClassMapper("LIST_TESTS", "ListTests");
|
||||||
|
addClassMapper("SET_TESTS", "SetTests");
|
||||||
|
addClassMapper("QUEUE_TESTS", "QueueTests");
|
||||||
|
addBiClassMapper("MAP_TESTS", "MapTests", "2");
|
||||||
|
|
||||||
//Abstract Classes
|
//Abstract Classes
|
||||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||||
@@ -191,6 +259,7 @@ public class GlobalVariables
|
|||||||
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
addAbstractMapper("ABSTRACT_LIST", "Abstract%sList");
|
||||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||||
addClassMapper("SUB_LIST", "SubList");
|
addClassMapper("SUB_LIST", "SubList");
|
||||||
|
addAbstractMapper("BASE_TASK", "Base%sTask");
|
||||||
|
|
||||||
//Helper Classes
|
//Helper Classes
|
||||||
addClassMapper("LISTS", "Lists");
|
addClassMapper("LISTS", "Lists");
|
||||||
@@ -202,6 +271,24 @@ public class GlobalVariables
|
|||||||
addClassMapper("ITERATORS", "Iterators");
|
addClassMapper("ITERATORS", "Iterators");
|
||||||
addClassMapper("ITERABLES", "Iterables");
|
addClassMapper("ITERABLES", "Iterables");
|
||||||
addBiClassMapper("MAPS", "Maps", "2");
|
addBiClassMapper("MAPS", "Maps", "2");
|
||||||
|
addClassMapper("SAMPLE_ELEMENTS", "Samples");
|
||||||
|
|
||||||
|
//UnitTest Helper Classes
|
||||||
|
addClassMapper("HELPERS", "Helpers");
|
||||||
|
addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator");
|
||||||
|
addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator");
|
||||||
|
addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator");
|
||||||
|
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");
|
||||||
|
addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator");
|
||||||
|
addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator");
|
||||||
|
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");
|
||||||
|
|
||||||
//Interfaces
|
//Interfaces
|
||||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||||
@@ -218,7 +305,9 @@ public class GlobalVariables
|
|||||||
addClassMapper("LIST_ITER", "ListIter");
|
addClassMapper("LIST_ITER", "ListIter");
|
||||||
addClassMapper("LIST", "List");
|
addClassMapper("LIST", "List");
|
||||||
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
||||||
|
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
|
||||||
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
||||||
|
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
|
||||||
addBiClassMapper("MAP", "Map", "2");
|
addBiClassMapper("MAP", "Map", "2");
|
||||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||||
addBiClassMapper("PAIR", "Pair", "");
|
addBiClassMapper("PAIR", "Pair", "");
|
||||||
@@ -226,18 +315,19 @@ public class GlobalVariables
|
|||||||
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
addClassMapper("PRIORITY_DEQUEUE", "PriorityDequeue");
|
||||||
addClassMapper("PREDICATE", "2BooleanFunction");
|
addClassMapper("PREDICATE", "2BooleanFunction");
|
||||||
addClassMapper("SORTED_SET", "SortedSet");
|
addClassMapper("SORTED_SET", "SortedSet");
|
||||||
|
addClassMapper("ORDERED_SET", "OrderedSet");
|
||||||
addClassMapper("SET", "Set");
|
addClassMapper("SET", "Set");
|
||||||
addClassMapper("STRATEGY", "Strategy");
|
addClassMapper("STRATEGY", "Strategy");
|
||||||
addClassMapper("STACK", "Stack");
|
addClassMapper("STACK", "Stack");
|
||||||
addClassMapper("SUPPLIER", "Supplier");
|
addClassMapper("SUPPLIER", "Supplier");
|
||||||
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
addAbstractMapper("SINGLE_UNARY_OPERATOR", "%1$s%1$sUnaryOperator");
|
||||||
|
addClassMapper("TASK", "Task");
|
||||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||||
if(type.isObject())
|
if(type.isObject())
|
||||||
{
|
{
|
||||||
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
|
if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer");
|
||||||
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
else addSimpleMapper("VALUE_CONSUMER", "Consumer");
|
||||||
addSimpleMapper("CONSUMER", "Consumer");
|
addSimpleMapper("CONSUMER", "Consumer");
|
||||||
addSimpleMapper("COMPARATOR", "Comparator");
|
|
||||||
addSimpleMapper("IARRAY", "IObjectArray");
|
addSimpleMapper("IARRAY", "IObjectArray");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -248,9 +338,10 @@ public class GlobalVariables
|
|||||||
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
|
addSimpleMapper("CONSUMER", type.getFileType()+"Consumer");
|
||||||
}
|
}
|
||||||
else addClassMapper("CONSUMER", "Consumer");
|
else addClassMapper("CONSUMER", "Consumer");
|
||||||
addClassMapper("COMPARATOR", "Comparator");
|
|
||||||
addFunctionMappers("IARRAY", "I%sArray");
|
addFunctionMappers("IARRAY", "I%sArray");
|
||||||
}
|
}
|
||||||
|
addSimpleMapper("VALUE_COMPARATOR", valueType.isObject() ? "Comparator" : String.format("%sComparator", valueType.getNonFileType()));
|
||||||
|
addSimpleMapper("COMPARATOR", type.isObject() ? "Comparator" : String.format("%sComparator", type.getNonFileType()));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,6 +391,7 @@ public class GlobalVariables
|
|||||||
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
|
addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get");
|
||||||
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
|
addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get");
|
||||||
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
|
addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream");
|
||||||
|
addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array");
|
||||||
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array");
|
||||||
addSimpleMapper("[SPACE]", " ");
|
addSimpleMapper("[SPACE]", " ");
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
package speiger.src.builder;
|
package speiger.src.builder;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
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.Arrays;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.StringJoiner;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import speiger.src.builder.processor.TemplateProcess;
|
import speiger.src.builder.processor.TemplateProcess;
|
||||||
import speiger.src.builder.processor.TemplateProcessor;
|
import speiger.src.builder.processor.TemplateProcessor;
|
||||||
@@ -19,6 +26,7 @@ import speiger.src.builder.processor.TemplateProcessor;
|
|||||||
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||||
{
|
{
|
||||||
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
|
||||||
|
EnumMap<ClassType, List<Predicate<String>>> blockedPredicate = new EnumMap<>(ClassType.class);
|
||||||
Map<String, String> nameRemapper = new HashMap<>();
|
Map<String, String> nameRemapper = new HashMap<>();
|
||||||
Map<String, String> biRequired = new HashMap<>();
|
Map<String, String> biRequired = new HashMap<>();
|
||||||
Set<String> enumRequired = new HashSet<>();
|
Set<String> enumRequired = new HashSet<>();
|
||||||
@@ -26,15 +34,39 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
List<GlobalVariables> variables = new ArrayList<>();
|
List<GlobalVariables> variables = new ArrayList<>();
|
||||||
List<GlobalVariables> biVariables = new ArrayList<>();
|
List<GlobalVariables> biVariables = new ArrayList<>();
|
||||||
List<GlobalVariables> enumVariables = new ArrayList<>();
|
List<GlobalVariables> enumVariables = new ArrayList<>();
|
||||||
|
boolean special = false;
|
||||||
|
|
||||||
public PrimitiveCollectionsBuilder()
|
public PrimitiveCollectionsBuilder()
|
||||||
{
|
{
|
||||||
super(Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimitiveCollectionsBuilder(boolean silencedSuccess)
|
||||||
|
{
|
||||||
|
super(silencedSuccess, Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||||
{
|
{
|
||||||
super(sourceFolder, outputFolder, dataFolder);
|
this(false, sourceFolder, outputFolder, dataFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
|
||||||
|
{
|
||||||
|
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrimitiveCollectionsBuilder setSpecial() {
|
||||||
|
special = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrimitiveCollectionsBuilder createTests(boolean silent) {
|
||||||
|
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/")).setSpecial();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrimitiveCollectionsBuilder createTesters(boolean silent) {
|
||||||
|
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/")).setSpecial();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,6 +87,23 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void afterFinish()
|
||||||
|
{
|
||||||
|
if(!special && getVersion() > 8)
|
||||||
|
{
|
||||||
|
Path basePath = Paths.get("src/main/java");
|
||||||
|
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
||||||
|
{
|
||||||
|
writer.write(getModuleInfo(basePath));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init()
|
protected void init()
|
||||||
{
|
{
|
||||||
@@ -73,7 +122,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
biRequired.put("Pair", "");
|
biRequired.put("Pair", "");
|
||||||
biRequired.put("MutablePair", "");
|
biRequired.put("MutablePair", "");
|
||||||
biRequired.put("ImmutablePair", "");
|
biRequired.put("ImmutablePair", "");
|
||||||
addBiClass("Function", "Maps", "Map", "SortedMap", "NavigableMap", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
nameRemapper.put("BiConsumer", "%sConsumer");
|
||||||
nameRemapper.put("IArray", "I%sArray");
|
nameRemapper.put("IArray", "I%sArray");
|
||||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
||||||
@@ -84,12 +133,54 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
nameRemapper.put("EnumMap", "Enum2%sMap");
|
||||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
||||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
nameRemapper.put("ImmutableList", "Immutable%sList");
|
||||||
|
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
||||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
||||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
||||||
|
|
||||||
|
|
||||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
||||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||||
addBlockage(ClassType.BOOLEAN, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||||
|
|
||||||
|
//UnitTesters
|
||||||
|
nameRemapper.put("AbstractIteratorTester", "Abstract%sIteratorTester");
|
||||||
|
nameRemapper.put("MinimalCollection", "Minimal%sCollection");
|
||||||
|
nameRemapper.put("MinimalSet", "Minimal%sSet");
|
||||||
|
nameRemapper.put("TestCollectionGenerator", "Test%sCollectionGenerator");
|
||||||
|
nameRemapper.put("TestQueueGenerator", "Test%sQueueGenerator");
|
||||||
|
nameRemapper.put("TestListGenerator", "Test%sListGenerator");
|
||||||
|
nameRemapper.put("TestNavigableSetGenerator", "Test%sNavigableSetGenerator");
|
||||||
|
nameRemapper.put("TestSortedSetGenerator", "Test%sSortedSetGenerator");
|
||||||
|
nameRemapper.put("TestOrderedSetGenerator", "Test%sOrderedSetGenerator");
|
||||||
|
nameRemapper.put("TestSetGenerator", "Test%sSetGenerator");
|
||||||
|
nameRemapper.put("AbstractContainerTester", "Abstract%sContainerTester");
|
||||||
|
nameRemapper.put("AbstractCollectionTester", "Abstract%sCollectionTester");
|
||||||
|
nameRemapper.put("AbstractQueueTester", "Abstract%sQueueTester");
|
||||||
|
nameRemapper.put("AbstractListTester", "Abstract%sListTester");
|
||||||
|
nameRemapper.put("AbstractListIndexOfTester", "Abstract%sListIndexOfTester");
|
||||||
|
nameRemapper.put("AbstractSetTester", "Abstract%sSetTester");
|
||||||
|
nameRemapper.put("SimpleTestGenerator", "Simple%sTestGenerator");
|
||||||
|
nameRemapper.put("SimpleQueueTestGenerator", "Simple%sQueueTestGenerator");
|
||||||
|
nameRemapper.put("TestMapGenerator", "Test%sMapGenerator");
|
||||||
|
nameRemapper.put("TestSortedMapGenerator", "Test%sSortedMapGenerator");
|
||||||
|
nameRemapper.put("TestOrderedMapGenerator", "Test%sOrderedMapGenerator");
|
||||||
|
nameRemapper.put("SimpleMapTestGenerator", "Simple%sMapTestGenerator");
|
||||||
|
nameRemapper.put("DerivedMapGenerators", "Derived%sMapGenerators");
|
||||||
|
nameRemapper.put("AbstractMapTester", "Abstract%sMapTester");
|
||||||
|
nameRemapper.put("TestMap", "Test%sMap");
|
||||||
|
biRequired.put("PairTester", "");
|
||||||
|
|
||||||
|
addBiClass("TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "OrderedMapTestSuiteBuilder", "MapTests", "MapConstructorTests", "TestMap");
|
||||||
|
addBiClass("MapAddToTester", "MapSubFromTester", "MapClearTester", "MapComputeIfAbsentTester", "MapComputeIfPresentTester", "MapComputeTester", "MapCopyTester", "MapContainsTester", "MapContainsKeyTester", "MapContainsValueTester", "MapCreatorTester", "MapEntrySetTester",
|
||||||
|
"MapEqualsTester", "MapForEachTester", "MapGetOrDefaultTester", "MapGetTester", "MapHashCodeTester", "MapIsEmptyTester", "MapMergeTester", "MapMergeBulkTester", "MapPutAllArrayTester", "MapPutAllTester", "MapPutIfAbsentTester", "MapPutTester",
|
||||||
|
"MapRemoveEntryTester", "MapRemoveOrDefaultTester", "MapRemoveTester", "MapReplaceAllTester", "MapReplaceEntryTester", "MapReplaceTester", "MapSizeTester", "MapSupplyIfAbsentTester", "MapToStringTester",
|
||||||
|
"NavigableMapNavigationTester", "SortedMapNavigationTester", "OrderedMapNavigationTester", "OrderedMapMoveTester", "MapConstructorTester");
|
||||||
|
|
||||||
|
addBlockage(ClassType.OBJECT, "CollectionStreamTester", "ListFillBufferTester");
|
||||||
|
addBlockage(ClassType.BOOLEAN, "TestOrderedSetGenerator", "TestSortedSetGenerator", "TestNavigableSetGenerator", "CollectionRemoveIfTester", "CollectionStreamTester", "ListFillBufferTester", "ListReplaceAllTester", "NavigableSetNavigationTester", "SetTests", "MapConstructorTests", "TestMap", "QueueTests");
|
||||||
|
addBlockage(ClassType.BOOLEAN, "OrderedSetMoveTester", "OrderedSetNavigationTester", "SortedSetNaviationTester", "SetTestSuiteBuilder", "OrderedSetTestSuiteBuilder", "SortedSetTestSuiteBuilder", "NavigableSetTestSuiteBuilder", "SortedSetSubsetTestSetGenerator", "OrderedMapNavigationTester", "OrderedMapTestSuiteBuilder", "OrderedSetIterationTester", "SortedSetIterationTester");
|
||||||
|
addBlockage(ClassType.BOOLEAN, "TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "MapTests");
|
||||||
|
addBlockage(ClassType.BOOLEAN, T -> T.endsWith("Tester") && (T.startsWith("Iterable") ||T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void create(ClassType mainType, ClassType subType)
|
protected void create(ClassType mainType, ClassType subType)
|
||||||
@@ -114,6 +205,11 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addBlockage(ClassType type, Predicate<String> filter)
|
||||||
|
{
|
||||||
|
blockedPredicate.computeIfAbsent(type, T -> new ArrayList<>()).add(filter);
|
||||||
|
}
|
||||||
|
|
||||||
protected void addBlockage(ClassType type, String...args)
|
protected void addBlockage(ClassType type, String...args)
|
||||||
{
|
{
|
||||||
for(String s : args)
|
for(String s : args)
|
||||||
@@ -134,45 +230,101 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
String splitter = biRequired.get(name);
|
String splitter = biRequired.get(name);
|
||||||
boolean valueRequired = enumRequired.contains(name);
|
boolean valueRequired = enumRequired.contains(name);
|
||||||
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
List<GlobalVariables> vars = getVariablesByClass(name, splitter != null);
|
||||||
EnumSet<ClassType> types = blocked.get(name);
|
|
||||||
for(int i = 0,m=vars.size();i<m;i++)
|
for(int i = 0,m=vars.size();i<m;i++)
|
||||||
{
|
{
|
||||||
GlobalVariables type = vars.get(i);
|
GlobalVariables type = vars.get(i);
|
||||||
if(types == null || !types.contains(type.getType()))
|
if(isAllowed(type.getType(), name))
|
||||||
{
|
{
|
||||||
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
acceptor.accept(type.create(nameRemapper.getOrDefault(name, "%s"+name), splitter, valueRequired));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isAllowed(ClassType type, String fileName)
|
||||||
|
{
|
||||||
|
EnumSet<ClassType> types = blocked.get(fileName);
|
||||||
|
if(types != null && types.contains(type)) return false;
|
||||||
|
List<Predicate<String>> list = blockedPredicate.get(type);
|
||||||
|
if(list != null) {
|
||||||
|
for(int i = 0,m=list.size();i<m;i++) {
|
||||||
|
if(list.get(i).test(fileName)) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
protected List<GlobalVariables> getVariablesByClass(String name, boolean bi) {
|
||||||
if(enumRequired.contains(name)) return enumVariables;
|
if(enumRequired.contains(name)) return enumVariables;
|
||||||
if(bi) return biVariables;
|
if(bi) return biVariables;
|
||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getModuleInfo(Path basePath) {
|
||||||
|
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
||||||
|
try(Stream<Path> stream = Files.walk(getOutputFolder()))
|
||||||
|
{
|
||||||
|
stream.filter(Files::isDirectory)
|
||||||
|
.filter(this::containsFiles)
|
||||||
|
.map(basePath::relativize)
|
||||||
|
.map(Path::toString)
|
||||||
|
.map(this::sanitize)
|
||||||
|
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("/** @author Speiger */\n");
|
||||||
|
builder.append("module ").append(sanitize(basePath.relativize(getOutputFolder()).toString())).append(" {\n");
|
||||||
|
builder.append(joiner.toString()).append("}");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String sanitize(String input)
|
||||||
|
{
|
||||||
|
return input.replace("\\", ".").replace("/", ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsFiles(Path path)
|
||||||
|
{
|
||||||
|
try(Stream<Path> stream = Files.walk(path, 1))
|
||||||
|
{
|
||||||
|
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getVersion()
|
||||||
|
{
|
||||||
|
String version = System.getProperty("java.version");
|
||||||
|
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||||
|
int dot = version.indexOf(".");
|
||||||
|
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String...args)
|
public static void main(String...args)
|
||||||
{
|
{
|
||||||
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 == 3) {
|
boolean forceTests = flags.contains("force-tests");
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
|
||||||
} else if(args.length == 4) {
|
new PrimitiveCollectionsBuilder(silent).process(force);
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
if(tests) {
|
||||||
} else {
|
createTests(silent).process(force || forceTests);
|
||||||
System.out.println("Invalid argument count passed in");
|
createTesters(silent).process(force || forceTests);
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InterruptedException e)
|
catch(InterruptedException | IOException e)
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,6 @@ import java.util.AbstractCollection;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|
||||||
#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.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -100,7 +99,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||||
* @param c the elements that should be checked for
|
* @param c the elements that should be checked for
|
||||||
* @return true if any element is in this collection
|
* @return true if any element is in this collection
|
||||||
* @deprecated if this is a primitive collection
|
|
||||||
* @throws java.lang.NullPointerException if the collection is null
|
* @throws java.lang.NullPointerException if the collection is null
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -232,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;
|
||||||
}
|
}
|
||||||
@@ -258,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+46
-1
@@ -5,16 +5,24 @@ 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;
|
||||||
|
|
||||||
#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.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.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;
|
||||||
@@ -83,6 +91,16 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
@Override
|
@Override
|
||||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Async Builder for moving work of the thread.
|
||||||
|
* It is not designed to split the work to multithreaded work, so using this keep it singlethreaded, but it allows to be moved to another thread.
|
||||||
|
* @see ASYNC_BUILDER
|
||||||
|
* @return a AsyncBuilder
|
||||||
|
*/
|
||||||
|
default ASYNC_BUILDER KEY_GENERIC_TYPE asAsync() {
|
||||||
|
return new ASYNC_BUILDERBRACES(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
|
||||||
* @param mapper the mapping function
|
* @param mapper the mapping function
|
||||||
@@ -140,6 +158,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
|
||||||
@@ -160,6 +187,24 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
|
||||||
|
* @return a new ArrayList of all elements
|
||||||
|
*/
|
||||||
|
default LIST KEY_GENERIC_TYPE pourAsList() {
|
||||||
|
return pour(new ARRAY_LISTBRACES());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
|
||||||
|
* @return a new LinkedHashSet of all elements
|
||||||
|
*/
|
||||||
|
default SET KEY_GENERIC_TYPE pourAsSet() {
|
||||||
|
return pour(new LINKED_HASH_SETBRACES());
|
||||||
|
}
|
||||||
|
|
||||||
|
#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.
|
||||||
* @param filter that should be applied
|
* @param filter that should be applied
|
||||||
|
|||||||
+4
@@ -50,6 +50,10 @@ public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
|||||||
{
|
{
|
||||||
COMPARATOR original;
|
COMPARATOR original;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default constructor
|
||||||
|
* @param original that is going to be reversed
|
||||||
|
*/
|
||||||
public Reversed(COMPARATOR original) {
|
public Reversed(COMPARATOR original) {
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.functions;
|
||||||
|
|
||||||
|
import java.util.concurrent.RunnableFuture;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* A Type Specific Task interface that allows you to keep track of the task that is currently running.<br>
|
||||||
|
* It extends Runnable future and supports said functions but also provides quality of life functions like:<br>
|
||||||
|
*
|
||||||
|
* - isSuccesfull: which allows to detect if the task was completed properly and not interrupted or crashed.
|
||||||
|
* - pause/resume: which allows to pause/resume the task at any moment, making it easier to create thread-safe actions.
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public interface TASK KEY_GENERIC_TYPE extends RunnableFuture<CLASS_TYPE> {
|
||||||
|
/**
|
||||||
|
* Helper function to detect if the task is currently paused.
|
||||||
|
* @return true if paused
|
||||||
|
*/
|
||||||
|
public boolean isPaused();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses the task, which lets the thread finish without completing the task.
|
||||||
|
* Tasks are written in the way where they can pause without any issues.
|
||||||
|
* This won't be instant, as this function is applied asynchronous and doesn't check if the thread paused.
|
||||||
|
* So make sure it had the time to pause.
|
||||||
|
*/
|
||||||
|
public void pause();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pauses the task, which lets the thread finish without completing the task.
|
||||||
|
* Tasks are written in the way where they can pause without any issues.
|
||||||
|
* This won't be instant, as this function is applied asynchronous.
|
||||||
|
* It will await the pausing of the task.
|
||||||
|
*/
|
||||||
|
public void awaitPausing();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continues the task if it wasn't already completed.
|
||||||
|
* This is done by resubmitting the task to the executor provided.
|
||||||
|
*/
|
||||||
|
public void resume();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quality of life function that allows to detect if no cancellation/exception was applied to this task and it completed on its own.
|
||||||
|
* @return true if it was properly completed
|
||||||
|
*/
|
||||||
|
public boolean isSuccessful();
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Type Specific get method that allows to reduce (un)boxing of primtives.
|
||||||
|
*
|
||||||
|
* Waits if necessary for the computation to complete, and then
|
||||||
|
* retrieves its result.
|
||||||
|
*
|
||||||
|
* @return the computed result as primitive
|
||||||
|
* @throws CancellationException if the computation was cancelled
|
||||||
|
* @throws ExecutionException if the computation threw an exception
|
||||||
|
* @throws InterruptedException if the current thread was interrupted
|
||||||
|
* while waiting
|
||||||
|
*/
|
||||||
|
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Waits if necessary for at most the given time for the computation
|
||||||
|
* to complete, and then retrieves its result, if available.
|
||||||
|
*
|
||||||
|
* @param timeout the maximum time to wait
|
||||||
|
* @param unit the time unit of the timeout argument
|
||||||
|
* @return the computed result as primitive
|
||||||
|
* @throws CancellationException if the computation was cancelled
|
||||||
|
* @throws ExecutionException if the computation threw an exception
|
||||||
|
* @throws InterruptedException if the current thread was interrupted while waiting
|
||||||
|
* @throws TimeoutException if the wait timed out
|
||||||
|
*/
|
||||||
|
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_TYPE get() throws InterruptedException, ExecutionException { return KEY_TO_OBJ(GET_KEY()); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_TYPE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return KEY_TO_OBJ(GET_KEY(timeout, unit)); }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+28
-16
@@ -75,7 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return index of the value that was searched for. -1 if not found
|
* @return index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -103,7 +103,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return the last index of the value that was searched for. -1 if not found
|
* @return the last index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-8
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,12 +189,25 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ArrayList with a EmptyObject array of the Type requested
|
||||||
|
* @param c the type of the array
|
||||||
|
* @param size the initial size of the backing array
|
||||||
|
* @Type(T)
|
||||||
|
* @return a typed List
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c, int size) {
|
||||||
|
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, size);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* Appends the specified element to the end of this list.
|
* Appends the specified element to the end of this list.
|
||||||
*
|
*
|
||||||
* @param e element to be appended to this list
|
* @param e element to be appended to this list
|
||||||
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
* @return true (as specified by {@link Collection#add})
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE e) {
|
public boolean add(KEY_TYPE e) {
|
||||||
@@ -232,6 +246,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
* @param index the index where to append the elements to
|
* @param index the index where to append the elements to
|
||||||
* @param c the elements to append to the list
|
* @param c the elements to append to the list
|
||||||
* @throws IndexOutOfBoundsException if index is outside of the lists range
|
* @throws IndexOutOfBoundsException if index is outside of the lists range
|
||||||
|
* @throws NullPointerException if collection contains a null element
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -239,6 +254,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
if(c instanceof COLLECTION) return addAll(index, (COLLECTION KEY_GENERIC_TYPE)c);
|
if(c instanceof COLLECTION) return addAll(index, (COLLECTION KEY_GENERIC_TYPE)c);
|
||||||
int add = c.size();
|
int add = c.size();
|
||||||
if(add <= 0) return false;
|
if(add <= 0) return false;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(c.contains(null)) throw new NullPointerException();
|
||||||
|
#endif
|
||||||
grow(size + add);
|
grow(size + add);
|
||||||
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
|
if(index != size) System.arraycopy(data, index, data, index+add, size - index);
|
||||||
size+=add;
|
size+=add;
|
||||||
@@ -307,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);
|
||||||
}
|
}
|
||||||
@@ -344,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
|
||||||
@@ -364,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);
|
||||||
for(int i = 0;i<length;i++)
|
|
||||||
data[i+to] = null;
|
|
||||||
size -= length;
|
size -= length;
|
||||||
|
for(int i = 0;i<length;i++)
|
||||||
|
data[i+size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1126,7 +1145,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void grow(int capacity) {
|
protected void grow(int capacity) {
|
||||||
if(capacity < data.length) return;
|
if(capacity <= data.length) return;
|
||||||
data = Arrays.copyOf(data, data == ARRAYS.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
|
data = Arrays.copyOf(data, data == ARRAYS.EMPTY_ARRAY ? Math.max(DEFAULT_ARRAY_SIZE, capacity) : (int)Math.max(Math.min((long)data.length + (data.length >> 1), SanityChecks.MAX_ARRAY_SIZE), capacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2176
File diff suppressed because it is too large
Load Diff
+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;
|
||||||
}
|
}
|
||||||
|
|||||||
+73
-60
@@ -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;
|
||||||
}
|
}
|
||||||
|
else if(before.next != last) {
|
||||||
Entry KEY_GENERIC_TYPE temp = last;
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
last = temp.prev;
|
last = temp.prev;
|
||||||
last.next = null;
|
last.next = null;
|
||||||
temp.next = before.next;
|
temp.next = before.next;
|
||||||
temp.prev = before;
|
temp.prev = before;
|
||||||
before.next = temp;
|
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;
|
||||||
}
|
}
|
||||||
|
else if(before.next != last) {
|
||||||
Entry KEY_GENERIC_TYPE temp = last;
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
last = temp.prev;
|
last = temp.prev;
|
||||||
last.next = null;
|
last.next = null;
|
||||||
temp.next = before.next;
|
temp.next = before.next;
|
||||||
temp.prev = before;
|
temp.prev = before;
|
||||||
before.next = temp;
|
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
|
||||||
|
|||||||
+2447
File diff suppressed because it is too large
Load Diff
+15
-58
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -10,7 +9,6 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
@@ -21,10 +19,9 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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.SORTED_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;
|
||||||
@@ -59,8 +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.ObjectSortedSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
|
|
||||||
@@ -71,7 +67,7 @@ import speiger.src.collections.utils.HashUtil;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -288,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);
|
||||||
@@ -310,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);
|
||||||
@@ -363,20 +359,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_ENTRY_KEY() {
|
public KEY_TYPE FIRST_ENTRY_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
@@ -387,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)) {
|
||||||
@@ -411,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)) {
|
||||||
@@ -438,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
|
||||||
@@ -473,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;
|
||||||
}
|
}
|
||||||
@@ -620,7 +600,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
values = newValues;
|
values = newValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -860,20 +840,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
public void clear() {
|
public void clear() {
|
||||||
LINKED_CUSTOM_HASH_MAP.this.clear();
|
LINKED_CUSTOM_HASH_MAP.this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -1092,18 +1061,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||||
|
|||||||
+28
-6
@@ -286,6 +286,15 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) {
|
||||||
|
int slot = findIndex(key);
|
||||||
|
if(slot < 0) return getDefaultReturnValue();
|
||||||
|
VALUE_TYPE oldValue = values[slot];
|
||||||
|
values[slot] -= value;
|
||||||
|
if(value < 0 ? (values[slot] >= getDefaultReturnValue()) : (values[slot] <= getDefaultReturnValue())) removeIndex(slot);
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@@ -307,6 +316,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(VALUE_TYPE value) {
|
public boolean containsValue(VALUE_TYPE value) {
|
||||||
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
for(int i = nullIndex;i >= 0;i--)
|
for(int i = nullIndex;i >= 0;i--)
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && VALUE_EQUALS(values[i], value)) return true;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && VALUE_EQUALS(values[i], value)) return true;
|
||||||
return false;
|
return false;
|
||||||
@@ -316,7 +326,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
@ValuePrimitive
|
@ValuePrimitive
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
for(int i = nullIndex;i >= 0;i--)
|
#if VALUE_OBJECT
|
||||||
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
|
#else
|
||||||
|
if(containsNull && ((value == null && values[nullIndex] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[nullIndex], value))) return true;
|
||||||
|
#endif
|
||||||
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
#if VALUE_OBJECT
|
#if VALUE_OBJECT
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||||
#else
|
#else
|
||||||
@@ -379,7 +394,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;
|
||||||
@@ -613,7 +632,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);
|
||||||
}
|
}
|
||||||
@@ -624,7 +643,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;
|
||||||
}
|
}
|
||||||
@@ -654,6 +673,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)) {
|
||||||
@@ -927,7 +949,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;
|
||||||
@@ -1158,7 +1180,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;
|
||||||
@@ -1314,7 +1336,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;
|
||||||
|
|||||||
+18
-64
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -10,7 +9,6 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
@@ -21,10 +19,9 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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.SORTED_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;
|
||||||
@@ -58,8 +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.ObjectSortedSet;
|
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
|
|
||||||
@@ -70,7 +66,7 @@ import speiger.src.collections.utils.HashUtil;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -265,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);
|
||||||
@@ -287,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);
|
||||||
@@ -367,20 +363,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_ENTRY_KEY() {
|
public KEY_TYPE FIRST_ENTRY_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
@@ -391,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)) {
|
||||||
@@ -415,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)) {
|
||||||
@@ -442,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
|
||||||
@@ -477,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;
|
||||||
}
|
}
|
||||||
@@ -624,7 +604,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
values = newValues;
|
values = newValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -861,20 +841,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
public void clear() {
|
public void clear() {
|
||||||
LINKED_HASH_MAP.this.clear();
|
LINKED_HASH_MAP.this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -904,9 +873,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE o) {
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
@@ -1088,23 +1055,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1){
|
||||||
if(filter.TEST_VALUE(keys[index])) return result++;
|
if(filter.TEST_VALUE(keys[index])) result++;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||||
@@ -1370,7 +1325,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
public void add(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapIterator {
|
private class MapIterator {
|
||||||
@@ -1440,7 +1394,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
if(previous == -1) firstIndex = next;
|
if(previous == -1) firstIndex = next;
|
||||||
else links[previous] ^= ((links[previous] ^ (next & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
else links[previous] ^= ((links[previous] ^ (next & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
|
||||||
if (next == -1) lastIndex = previous;
|
if(next == -1) lastIndex = previous;
|
||||||
else links[next] ^= ((links[next] ^ ((previous & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
else links[next] ^= ((links[next] ^ ((previous & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||||
if(current == nullIndex) {
|
if(current == nullIndex) {
|
||||||
current = -1;
|
current = -1;
|
||||||
|
|||||||
+29
-7
@@ -261,6 +261,15 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
return oldValue;
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) {
|
||||||
|
int slot = findIndex(key);
|
||||||
|
if(slot < 0) return getDefaultReturnValue();
|
||||||
|
VALUE_TYPE oldValue = values[slot];
|
||||||
|
values[slot] -= value;
|
||||||
|
if(value < 0 ? (values[slot] >= getDefaultReturnValue()) : (values[slot] <= getDefaultReturnValue())) removeIndex(slot);
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@@ -278,7 +287,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(VALUE_TYPE value) {
|
public boolean containsValue(VALUE_TYPE value) {
|
||||||
for(int i = nullIndex;i >= 0;i--)
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -287,7 +297,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
@ValuePrimitive
|
@ValuePrimitive
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
for(int i = nullIndex;i >= 0;i--)
|
#if VALUE_OBJECT
|
||||||
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
|
#else
|
||||||
|
if(containsNull && ((value == null && values[nullIndex] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[nullIndex], value))) return true;
|
||||||
|
#endif
|
||||||
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
#if VALUE_OBJECT
|
#if VALUE_OBJECT
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||||
#else
|
#else
|
||||||
@@ -347,7 +362,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;
|
||||||
@@ -574,7 +593,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);
|
||||||
}
|
}
|
||||||
@@ -585,7 +604,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;
|
||||||
}
|
}
|
||||||
@@ -614,6 +633,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)) {
|
||||||
@@ -887,7 +909,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;
|
||||||
@@ -1114,7 +1136,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;
|
||||||
@@ -1270,7 +1292,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;
|
||||||
|
|||||||
+17
-48
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.impl.immutable;
|
package speiger.src.collections.PACKAGE.maps.impl.immutable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -11,7 +10,6 @@ import java.util.function.BiFunction;
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
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.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||||
@@ -24,10 +22,12 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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;
|
||||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
#if !TYPE_OBJECT
|
||||||
|
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;
|
||||||
@@ -49,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,10 +69,9 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
|
||||||
#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;
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing keys array */
|
/** The Backing keys array */
|
||||||
protected transient KEY_TYPE[] keys;
|
protected transient KEY_TYPE[] keys;
|
||||||
@@ -103,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;
|
||||||
|
|
||||||
@@ -297,11 +295,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
@@ -432,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;
|
||||||
}
|
}
|
||||||
@@ -464,15 +462,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
@@ -528,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)) {
|
||||||
@@ -596,7 +588,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -809,20 +801,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() { throw new UnsupportedOperationException(); }
|
public void clear() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
|
||||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -1023,18 +1004,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||||
|
|||||||
+34
-1135
File diff suppressed because it is too large
Load Diff
+25
-4
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +181,18 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
return getDefaultReturnValue();
|
return getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(T key, VALUE_TYPE value) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
|
VALUE_TYPE oldValue = values[index];
|
||||||
|
values[index] -= value;
|
||||||
|
if(value < 0 ? (values[index] >= getDefaultReturnValue()) : (values[index] <= getDefaultReturnValue())) {
|
||||||
|
clear(index);
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
@@ -518,6 +531,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();
|
||||||
|
|||||||
+18
-58
@@ -1,6 +1,5 @@
|
|||||||
package speiger.src.collections.PACKAGE.maps.impl.misc;
|
package speiger.src.collections.PACKAGE.maps.impl.misc;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -10,16 +9,14 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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.SORTED_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;
|
||||||
@@ -31,8 +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.ObjectSortedSet;
|
|
||||||
import speiger.src.collections.objects.sets.ObjectSet;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +37,7 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
|||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE
|
public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected long[] links;
|
protected long[] links;
|
||||||
@@ -71,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,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];
|
||||||
}
|
}
|
||||||
@@ -252,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];
|
||||||
}
|
}
|
||||||
@@ -269,20 +264,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(T fromKey, T toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(T toKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(T fromKey) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T FIRST_ENTRY_KEY() {
|
public T FIRST_ENTRY_KEY() {
|
||||||
if(size == 0) throw new NoSuchElementException();
|
if(size == 0) throw new NoSuchElementException();
|
||||||
@@ -332,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
|
||||||
@@ -433,7 +414,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -558,20 +539,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
public void clear() {
|
public void clear() {
|
||||||
LINKED_ENUM_MAP.this.clear();
|
LINKED_ENUM_MAP.this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
@Override
|
|
||||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -684,17 +654,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(T fromElement, T toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(T toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(T fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||||
@@ -869,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() {
|
||||||
|
|||||||
+1397
-1240
File diff suppressed because it is too large
Load Diff
+1415
-1258
File diff suppressed because it is too large
Load Diff
+95
@@ -0,0 +1,95 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||||
|
* Since the interface adds nothing new. It is there just for completion sake.
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
return MAP.super.compute(key, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
return MAP.super.computeIfPresent(key, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||||
|
MAP.super.forEach(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
return MAP.super.merge(key, value, mappingFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object key, Object value);
|
||||||
|
@Override
|
||||||
|
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Primitive
|
||||||
|
@Override
|
||||||
|
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||||
|
return MAP.super.getOrDefault(key, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Primitive
|
||||||
|
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
|
return MAP.super.putIfAbsent(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default boolean remove(Object key, Object value) {
|
||||||
|
return MAP.super.remove(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||||
|
return MAP.super.replace(key, oldValue, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||||
|
return MAP.super.replace(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||||
|
MAP.super.replaceAll(mappingFunction);
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
-1
@@ -31,6 +31,7 @@ import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP;
|
|||||||
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||||
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||||
@@ -179,6 +180,17 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
*/
|
*/
|
||||||
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m);
|
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper method to subtract from primitive from each other. If the key is not present it will just return the defaultValue
|
||||||
|
* How the implementation works is that it will subtract from the current value (if not present it will do nothing) and fence it to the {@link #getDefaultReturnValue()}
|
||||||
|
* If the fence is reached the element will be automaticall removed
|
||||||
|
*
|
||||||
|
* @param key that should be subtract from
|
||||||
|
* @param value that should be subtract
|
||||||
|
* @return the last present or default return value
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* Type Specific function for the bull putting of values
|
* Type Specific function for the bull putting of values
|
||||||
@@ -545,8 +557,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
|
||||||
@@ -1369,6 +1381,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);
|
||||||
}
|
}
|
||||||
@@ -1497,6 +1510,14 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
|||||||
return putElements(new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy));
|
return putElements(new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the Keys and Values into a Concurrent Hash Map
|
||||||
|
* @return a CONCURRENT_HASH_MAP
|
||||||
|
*/
|
||||||
|
public CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE concurrentMap() {
|
||||||
|
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the Keys and Values into a Array Map
|
* Builds the Keys and Values into a Array Map
|
||||||
* @return a ARRAY_MAP
|
* @return a ARRAY_MAP
|
||||||
|
|||||||
+7
-5
@@ -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
|
||||||
@@ -207,13 +209,13 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
|||||||
default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey), true); }
|
default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey), true); }
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(CLASS_TYPE key) { return lowerEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(CLASS_TYPE key) { return floorEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(CLASS_TYPE key) { return ceilingEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(CLASS_TYPE key);
|
||||||
@Override
|
@Override
|
||||||
default MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(CLASS_TYPE key) { return higherEntry(OBJ_TO_KEY(key)); }
|
MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(CLASS_TYPE key);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive);
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive);
|
||||||
|
|||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||||
|
|
||||||
|
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.sets.ObjectOrderedSet;
|
||||||
|
/**
|
||||||
|
* A Special Map Interface giving Access to some really usefull functions
|
||||||
|
* The Idea behind this interface is to allow access to functions that give control to the Order of elements.
|
||||||
|
* Since Linked implementations as examples can be reordered outside of the Insertion Order.
|
||||||
|
* This interface provides basic access to such functions while also providing some Sorted/NaivgableMap implementations that still fit into here.
|
||||||
|
*
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A customized put method that allows you to insert into the first index.
|
||||||
|
* @param key the key that should be inserted
|
||||||
|
* @param value the value that should be inserted
|
||||||
|
* @return the previous present or default return value
|
||||||
|
* @see java.util.Map#put(Object, Object)
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
|
||||||
|
* @param key the key that should be inserted
|
||||||
|
* @param value the value that should be inserted
|
||||||
|
* @return the previous present or default return value
|
||||||
|
* @see java.util.Map#put(Object, Object)
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key/value to the first index.
|
||||||
|
* @param key that should be moved to the first index
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToFirst(KEY_TYPE key);
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key/value to the last index.
|
||||||
|
* @param key that should be moved to the first last
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToLast(KEY_TYPE key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Specific get method that allows to move teh given key/value int the first index.
|
||||||
|
* @param key that is searched for
|
||||||
|
* @return the given value for the requested key or default return value
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
|
||||||
|
/**
|
||||||
|
* A Specific get method that allows to move teh given key/value int the last index.
|
||||||
|
* @param key that is searched for
|
||||||
|
* @return the given value for the requested key or default return value
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first Key of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE FIRST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the first Key of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get the last Key of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE LAST_ENTRY_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the last Key of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_LAST_ENTRY_KEY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first Value of a Map.
|
||||||
|
* @return the first key in the map
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE FIRST_ENTRY_VALUE();
|
||||||
|
/**
|
||||||
|
* A method to get the last Value of a Map.
|
||||||
|
* @return the last key in the map
|
||||||
|
*/
|
||||||
|
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||||
|
@Override
|
||||||
|
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @return a new SortedMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is unmodifiable
|
||||||
|
* @return a new SortedMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
interface FastOrderedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
|
@Override
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||||
|
/**
|
||||||
|
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||||
|
* @param fromElement that is going to be started from.
|
||||||
|
* @return a improved iterator that starts from the desired element
|
||||||
|
*/
|
||||||
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
-56
@@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,60 +21,11 @@ import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
|||||||
*
|
*
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
|
* @note ORDERED_MAP is only extended until 0.6.0 for Compat reasons.
|
||||||
|
* The supported classes already implement ORDERED_MAP directly and will remove SORTED_MAP implementations in favor of ORDERED_MAP instead
|
||||||
*/
|
*/
|
||||||
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* A customized put method that allows you to insert into the first index.
|
|
||||||
* @param key the key that should be inserted
|
|
||||||
* @param value the value that should be inserted
|
|
||||||
* @return the previous present or default return value
|
|
||||||
* @see java.util.Map#put(Object, Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
|
|
||||||
/**
|
|
||||||
* A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
|
|
||||||
* @param key the key that should be inserted
|
|
||||||
* @param value the value that should be inserted
|
|
||||||
* @return the previous present or default return value
|
|
||||||
* @see java.util.Map#put(Object, Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key/value to the first index.
|
|
||||||
* @param key that should be moved to the first index
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToFirst(KEY_TYPE key);
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key/value to the last index.
|
|
||||||
* @param key that should be moved to the first last
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToLast(KEY_TYPE key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Specific get method that allows to move teh given key/value int the first index.
|
|
||||||
* @param key that is searched for
|
|
||||||
* @return the given value for the requested key or default return value
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
|
|
||||||
/**
|
|
||||||
* A Specific get method that allows to move teh given key/value int the last index.
|
|
||||||
* @param key that is searched for
|
|
||||||
* @return the given value for the requested key or default return value
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||||
|
|
||||||
@@ -80,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();
|
||||||
|
|
||||||
@@ -204,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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,6 +172,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
|||||||
interface FastSortedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
interface FastSortedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
@Override
|
@Override
|
||||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||||
|
/**
|
||||||
|
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||||
|
* @param fromElement that is going to be started from.
|
||||||
|
* @return a improved iterator that starts from the desired element
|
||||||
|
*/
|
||||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-6
@@ -82,7 +82,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
*/
|
*/
|
||||||
public ARRAY_FIFO_QUEUE(int capacity) {
|
public ARRAY_FIFO_QUEUE(int capacity) {
|
||||||
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
|
||||||
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity));
|
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity+1));
|
||||||
minCapacity = array.length;
|
minCapacity = array.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,16 +106,21 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
if(first != last) {
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
Arrays.fill(array, null);
|
Arrays.fill(array, null);
|
||||||
#endif
|
#endif
|
||||||
first = last = 0;
|
first = last = 0;
|
||||||
}
|
}
|
||||||
|
else if(first != 0) {
|
||||||
|
first = last = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enqueue(KEY_TYPE e) {
|
public void enqueue(KEY_TYPE e) {
|
||||||
array[last] = e;
|
array[last++] = e;
|
||||||
last = ++last % array.length;
|
if(last == array.length) last = 0;
|
||||||
if(last == first) expand();
|
if(last == first) expand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +138,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
array[first] = null;
|
array[first] = null;
|
||||||
#endif
|
#endif
|
||||||
first = ++first % array.length;
|
if(++first == array.length) first = 0;
|
||||||
reduce();
|
reduce();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -152,8 +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();
|
||||||
return array[(first + index) % array.length];
|
index += first;
|
||||||
|
return index >= array.length ? array[index-array.length] : array[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -428,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;
|
||||||
|
|||||||
+3
-2
@@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
||||||
@@ -70,7 +71,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
|
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
this.size = size;
|
|
||||||
comparator = comp;
|
comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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, 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Simple Heap base Priority Queue implementation
|
* A Simple Heap base Priority Queue implementation
|
||||||
@@ -66,7 +67,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
*/
|
*/
|
||||||
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
|
||||||
if(size > 0) array = NEW_KEY_ARRAY(size);
|
if(size > 0) array = NEW_KEY_ARRAY(size);
|
||||||
this.size = size;
|
|
||||||
comparator = comp;
|
comparator = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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, 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+540
-354
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,11 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
*/
|
*/
|
||||||
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+19
-374
@@ -3,7 +3,6 @@ package speiger.src.collections.PACKAGE.sets;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
@@ -21,7 +20,6 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
|||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
#endif
|
#endif
|
||||||
@@ -36,7 +34,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
|||||||
* This implementation does not shrink the backing array
|
* This implementation does not shrink the backing array
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing Array */
|
/** The Backing Array */
|
||||||
protected transient KEY_TYPE[] data;
|
protected transient KEY_TYPE[] data;
|
||||||
@@ -56,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +131,17 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
int index = findIndex(o);
|
||||||
|
if(index != -1) return data[index];
|
||||||
|
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||||
|
data[size++] = o;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||||
int index = findIndex(o);
|
int index = findIndex(o);
|
||||||
@@ -159,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;
|
||||||
@@ -499,28 +509,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(0, toIndex+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
if(fromIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, size - fromIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
||||||
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
||||||
set.data = Arrays.copyOf(data, data.length);
|
set.data = Arrays.copyOf(data, data.length);
|
||||||
@@ -528,11 +516,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
size = 0;
|
size = 0;
|
||||||
@@ -573,261 +556,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
|
||||||
int offset;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
SubSet(int offset, int length) {
|
|
||||||
this.offset = offset;
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end() { return offset+length; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean add(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
|
|
||||||
data[end()] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
System.arraycopy(data, offset, data, offset+1, size-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(index != 0) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
data[end()] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(index != 0) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset+1, data, offset, index-offset);
|
|
||||||
data[offset+length] = o;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index > offset) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1 && index < end()-1) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, index+1, data, index, end()-index-1);
|
|
||||||
data[end()-1] = o;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public boolean contains(KEY_TYPE e) {
|
|
||||||
return findIndex(e) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
public boolean contains(Object e) {
|
|
||||||
return findIndex(e) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE FIRST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
return data[offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE LAST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
return data[end()-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public boolean remove(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1) {
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
public boolean remove(Object o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1) {
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE POLL_FIRST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
KEY_TYPE result = data[offset];
|
|
||||||
System.arraycopy(data, offset+1, data, offset, size-offset);
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE POLL_LAST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
KEY_TYPE result = data[offset+length];
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
return new SetIterator(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
|
||||||
int index = findIndex(fromElement);
|
|
||||||
if(index != -1) return new SetIterator(index);
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubSet copy() { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(0, toIndex+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
if(fromIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, size - fromIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
||||||
if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
|
|
||||||
System.arraycopy(data, offset, a, 0, size());
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public Object[] toArray() {
|
|
||||||
Object[] obj = new Object[size()];
|
|
||||||
for(int i = 0;i<size();i++)
|
|
||||||
obj[i] = KEY_TO_OBJ(data[offset+i]);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Primitive
|
|
||||||
public <E> E[] toArray(E[] a) {
|
|
||||||
if(a == null) a = (E[])new Object[size()];
|
|
||||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
|
||||||
for(int i = 0;i<size();i++)
|
|
||||||
a[i] = (E)KEY_TO_OBJ(data[offset+i]);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
protected int findIndex(KEY_TYPE o) {
|
|
||||||
for(int i = length-1;i>=0;i--)
|
|
||||||
if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
protected int findIndex(Object o) {
|
|
||||||
for(int i = length-1;i>=0;i--)
|
|
||||||
if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
@@ -856,93 +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
|
|
||||||
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 {
|
|
||||||
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
|
@Override
|
||||||
@@ -981,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -991,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-19
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
@@ -15,7 +14,6 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
@@ -34,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* Extra to that there is a couple quality of life functions provided
|
* Extra to that there is a couple quality of life functions provided
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing keys array */
|
/** The Backing keys array */
|
||||||
protected transient KEY_TYPE[] keys;
|
protected transient KEY_TYPE[] keys;
|
||||||
@@ -241,6 +239,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) { throw new UnsupportedOperationException(); }
|
||||||
@@ -257,7 +259,12 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return containsNull;
|
if(o == null) return containsNull;
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -450,18 +457,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() { throw new UnsupportedOperationException(); }
|
public void clear() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@@ -507,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;
|
||||||
@@ -535,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];
|
||||||
}
|
}
|
||||||
@@ -545,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-29
@@ -1,7 +1,6 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
@@ -16,9 +15,6 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
#endif
|
|
||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -37,7 +33,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -127,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]);
|
||||||
}
|
}
|
||||||
@@ -241,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;
|
||||||
@@ -253,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;
|
||||||
@@ -286,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);
|
||||||
@@ -308,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);
|
||||||
@@ -374,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)) {
|
||||||
@@ -397,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)) {
|
||||||
@@ -512,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;
|
||||||
}
|
}
|
||||||
@@ -672,18 +668,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int previous = -1;
|
int previous = -1;
|
||||||
int next = -1;
|
int next = -1;
|
||||||
@@ -731,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();
|
||||||
@@ -789,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];
|
||||||
}
|
}
|
||||||
@@ -799,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-29
@@ -1,8 +1,5 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
import java.util.Comparator;
|
|
||||||
#endif
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -19,7 +16,6 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
@@ -38,7 +34,7 @@ import speiger.src.collections.utils.SanityChecks;
|
|||||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
*/
|
*/
|
||||||
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||||
protected transient long[] links;
|
protected transient long[] links;
|
||||||
@@ -114,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]);
|
||||||
}
|
}
|
||||||
@@ -212,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;
|
||||||
@@ -224,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;
|
||||||
@@ -257,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);
|
||||||
@@ -279,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);
|
||||||
@@ -345,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)) {
|
||||||
@@ -368,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)) {
|
||||||
@@ -603,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;
|
||||||
}
|
}
|
||||||
@@ -643,18 +639,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int previous = -1;
|
int previous = -1;
|
||||||
int next = -1;
|
int next = -1;
|
||||||
@@ -692,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;
|
||||||
@@ -760,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];
|
||||||
}
|
}
|
||||||
@@ -770,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -171,10 +171,10 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
|||||||
default CLASS_TYPE last() { return SORTED_SET.super.last(); }
|
default CLASS_TYPE last() { return SORTED_SET.super.last(); }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE pollFirst() { return KEY_TO_OBJ(POLL_FIRST_KEY()); }
|
public default CLASS_TYPE pollFirst() { return isEmpty() ? null : KEY_TO_OBJ(POLL_FIRST_KEY()); }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public default CLASS_TYPE pollLast() { return KEY_TO_OBJ(POLL_LAST_KEY()); }
|
public default CLASS_TYPE pollLast() { return isEmpty() ? null : KEY_TO_OBJ(POLL_LAST_KEY()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
+29
-5
@@ -277,6 +277,30 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||||
|
if(containsNull) return EMPTY_KEY_VALUE;
|
||||||
|
containsNull = true;
|
||||||
|
onNodeAdded(nullIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||||
|
KEY_TYPE current = keys[pos];
|
||||||
|
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
||||||
|
if(strategy.equals(current, o)) return current;
|
||||||
|
while(!strategy.equals((current = keys[pos = (++pos & mask)]), EMPTY_KEY_VALUE))
|
||||||
|
if(strategy.equals(current, o)) return current;
|
||||||
|
}
|
||||||
|
keys[pos] = o;
|
||||||
|
onNodeAdded(pos);
|
||||||
|
}
|
||||||
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
@@ -349,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;
|
||||||
@@ -361,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;
|
||||||
}
|
}
|
||||||
@@ -565,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;
|
||||||
|
|||||||
+39
-5
@@ -235,6 +235,30 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) {
|
||||||
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
|
if(containsNull) return null;
|
||||||
|
containsNull = true;
|
||||||
|
onNodeAdded(nullIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||||
|
KEY_TYPE current = keys[pos];
|
||||||
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
|
if(KEY_EQUALS(current, o)) return current;
|
||||||
|
while(KEY_EQUALS_NOT_NULL((current = keys[pos = (++pos & mask)])))
|
||||||
|
if(KEY_EQUALS(current, o)) return current;
|
||||||
|
}
|
||||||
|
keys[pos] = o;
|
||||||
|
onNodeAdded(pos);
|
||||||
|
}
|
||||||
|
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(Collection<? extends CLASS_TYPE> c) {
|
||||||
@@ -252,7 +276,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return containsNull;
|
if(o == null) return containsNull;
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -265,7 +294,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
if(o == null) return (containsNull ? removeNullIndex() : false);
|
if(o == null) return (containsNull ? removeNullIndex() : false);
|
||||||
|
#else
|
||||||
|
if(o == null) return false;
|
||||||
|
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return (containsNull ? removeNullIndex() : false);
|
||||||
|
#endif
|
||||||
int pos = HashUtil.mix(o.hashCode()) & mask;
|
int pos = HashUtil.mix(o.hashCode()) & mask;
|
||||||
KEY_TYPE current = keys[pos];
|
KEY_TYPE current = keys[pos];
|
||||||
if(KEY_EQUALS_NULL(current)) return false;
|
if(KEY_EQUALS_NULL(current)) return false;
|
||||||
@@ -306,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;
|
||||||
@@ -318,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;
|
||||||
}
|
}
|
||||||
@@ -418,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;
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Special Set Interface giving Access to some really usefull functions
|
||||||
|
* The Idea behind this interface is to allow access to functions that give control to the Order of elements.
|
||||||
|
* Since Linked implementations as examples can be reordered outside of the Insertion Order.
|
||||||
|
* This interface provides basic access to such functions while also providing some Sorted/NaivgableSet implementations that still fit into here.
|
||||||
|
*
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A customized add method that allows you to insert into the first index.
|
||||||
|
* @param o the element that should be inserted
|
||||||
|
* @return true if it was added
|
||||||
|
* @see java.util.Set#add(Object)
|
||||||
|
*/
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o);
|
||||||
|
/**
|
||||||
|
* A customized add method that allows you to insert into the last index.
|
||||||
|
* @param o the element that should be inserted
|
||||||
|
* @return true if it was added
|
||||||
|
* @see java.util.Set#add(Object)
|
||||||
|
*/
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key to the first index.
|
||||||
|
* @param o that should be moved to the first index
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToFirst(KEY_TYPE o);
|
||||||
|
/**
|
||||||
|
* A specific move method to move a given key to the last index.
|
||||||
|
* @param o that should be moved to the first last
|
||||||
|
* @return true if the value was moved.
|
||||||
|
* @note returns false if the value was not present in the first place
|
||||||
|
*/
|
||||||
|
public boolean moveToLast(KEY_TYPE o);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type Specific Iterator starting from a given key
|
||||||
|
* @param fromElement the element the iterator should start from
|
||||||
|
* @return a iterator starting from the given element
|
||||||
|
* @throws java.util.NoSuchElementException if fromElement isn't found
|
||||||
|
*/
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
|
* @return type specific splititerator
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method to get the first element in the set
|
||||||
|
* @return first element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE FIRST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the first element in the set
|
||||||
|
* @return first element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get the last element in the set
|
||||||
|
* @return last element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE LAST_KEY();
|
||||||
|
/**
|
||||||
|
* A method to get and remove the last element in the set
|
||||||
|
* @return last element in the set
|
||||||
|
*/
|
||||||
|
public KEY_TYPE POLL_LAST_KEY();
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is Synchronized
|
||||||
|
* @return a new OrderedSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new OrderedSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped OrderedSet that is unmodifiable
|
||||||
|
* @return a new OrderedSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default ORDERED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+538
-353
File diff suppressed because it is too large
Load Diff
@@ -54,6 +54,15 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
|||||||
return COLLECTION.super.remove(o);
|
return COLLECTION.super.remove(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* A Helper method that allows to add a element or getting the already present implement.
|
||||||
|
* Allowing to make unique references reuseable.
|
||||||
|
* @param o the element to add
|
||||||
|
* @return either the inserted element or the present element.
|
||||||
|
*/
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,44 +16,11 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
|||||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||||
* with a couple extra methods that allow greater control over sets.
|
* with a couple extra methods that allow greater control over sets.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
|
* @note ORDERED_SET is only extended until 0.6.0 for Compat reasons.
|
||||||
|
* The supported classes already implement ORDERED_SET directly and will remove SORTED_SET implementations in favor of ORDERED_SET instead
|
||||||
*/
|
*/
|
||||||
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the first index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the last index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the first index.
|
|
||||||
* @param o that should be moved to the first index
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the last index.
|
|
||||||
* @param o that should be moved to the first last
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Comparator method
|
* A Type Specific Comparator method
|
||||||
* @return the type specific comparator
|
* @return the type specific comparator
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+913
@@ -0,0 +1,913 @@
|
|||||||
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.concurrent.locks.LockSupport;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
|
#else
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.TASK;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||||
|
#endif
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
|
||||||
|
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
|
||||||
|
#endif
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||||
|
#endif
|
||||||
|
#if !TYPE_INT
|
||||||
|
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||||
|
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The Async API allows you to process collections on a different thread without having to deal with the Multithreading complexity. <br>
|
||||||
|
* It uses the Lightweight Stream Replace API to do its work, which can make it faster then sequential streams. <br>
|
||||||
|
* This feature isn't designed to do Multithreading work, but to allow moving work off the main thread into a worker thread. <br>
|
||||||
|
* So anything executed on this is still Singlethreaded. <br>
|
||||||
|
* <br>
|
||||||
|
* How it works is you create the AsyncBuilder using a Iterable of the Type. <br>
|
||||||
|
* Then select things you want to use on the Iterable. <br>
|
||||||
|
* - For example: map/filter/peek/limit/etc <br>
|
||||||
|
* <br>
|
||||||
|
* After that you select your action the Iterable should be applied on. <br>
|
||||||
|
* - For Example: forEach/findFirst/matchAny/etc <br>
|
||||||
|
* <br>
|
||||||
|
* Then optionally a custom Executor or callback can be applied <br>
|
||||||
|
* At the end either execute or join can be called to start the task. <br>
|
||||||
|
* - execute will return the Task reference so that the task can be traced back. <br>
|
||||||
|
* - join will await the completion of the task and return the return value <br>
|
||||||
|
* <br>
|
||||||
|
* During Construction a couple Disposable Builder Objects will be created. <br>
|
||||||
|
* These will be only used during construction. <br>
|
||||||
|
* <br>
|
||||||
|
* The Task Object is also pause-able/Interruptable at any moment during the Processing. <br>
|
||||||
|
*
|
||||||
|
* A small example
|
||||||
|
* <pre><code>
|
||||||
|
* 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)
|
||||||
|
* .onCompletion(T -> {}} //Callback on completion (Optional)
|
||||||
|
* .execute() //Starts the task. (Required)
|
||||||
|
* }
|
||||||
|
* </code></pre>
|
||||||
|
* @author Speiger
|
||||||
|
*
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
BASE_TASK KEY_GENERIC_TYPE task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main Constructor that uses a Iterable to build a Offthread Task.
|
||||||
|
* @param iterable that should be processed
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper constructor.
|
||||||
|
* @param task that had been build
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER(BASE_TASK KEY_GENERIC_TYPE task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that automatically wraps a Iterable into a AsyncBuilder since it forces this collections Iterable.
|
||||||
|
* @param iterable that should be wrapped
|
||||||
|
* @Type(T)
|
||||||
|
* @return a AsyncBuilder with the iterable wrapped
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ASYNC_BUILDER KEY_GENERIC_TYPE of(Iterable<CLASS_TYPE> 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
|
||||||
|
* @param mapper the mapping function
|
||||||
|
* @param <E> The return type.
|
||||||
|
* @return a new Builder Object with the mapped Iterable
|
||||||
|
*/
|
||||||
|
public <E> ObjectAsyncBuilder<E> map(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||||
|
return new ObjectAsyncBuilder<>(ITERABLES.map(iterable, mapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the elements to something else
|
||||||
|
* @param mapper the flatMapping function
|
||||||
|
* @param <V> The return type supplier.
|
||||||
|
* @param <E> The return type.
|
||||||
|
* @return a new Builder Object with the mapped Iterable
|
||||||
|
*/
|
||||||
|
public <E, V extends Iterable<E>> ObjectAsyncBuilder<E> flatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||||
|
return new ObjectAsyncBuilder<>(ITERABLES.flatMap(iterable, mapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the elements to something else
|
||||||
|
* @param mapper the flatMapping function
|
||||||
|
* @param <E> The return type.
|
||||||
|
* @return a new Builder Object with the mapped Iterable
|
||||||
|
*/
|
||||||
|
public <E> ObjectAsyncBuilder<E> arrayflatMap(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||||
|
return new ObjectAsyncBuilder<>(ITERABLES.arrayFlatMap(iterable, mapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters out the unwanted elements out of the Iterable
|
||||||
|
* @param filter the elements that should be kept
|
||||||
|
* @return Self with a filter applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE filter(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
iterable = ITERABLES.filter(iterable, filter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes duplicated elements out of the Iterable
|
||||||
|
* @return Self with a deduplicator applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE distinct() {
|
||||||
|
iterable = ITERABLES.distinct(iterable);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limits how many elements are inside of the Iterable
|
||||||
|
* @param limit how many elements should max be iterated through
|
||||||
|
* @return self with a limiter applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE limit(long limit) {
|
||||||
|
iterable = ITERABLES.limit(iterable, limit);
|
||||||
|
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
|
||||||
|
* @param action the action that should be applied
|
||||||
|
* @return self with a preview applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
iterable = ITERABLES.peek(iterable, action);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates over the Iterable with a desired action
|
||||||
|
* @param action that should be applied
|
||||||
|
* @return a new Builder with the forEach action applied.
|
||||||
|
*/
|
||||||
|
public ObjectAsyncBuilder<Void> forEach(CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new ObjectAsyncBuilder<>(new ForEachTask<>(iterable.iterator(), action));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reduces the elements inside of the Iterable down to one element
|
||||||
|
* @param operator that reduces the elements.
|
||||||
|
* @return self with the reduce action applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
task = new SimpleReduceTaskBRACES(iterable.iterator(), operator);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* Reduces the elements inside of the Iterable down to one element using a identity element.
|
||||||
|
* @param <E> the return type
|
||||||
|
* @param identity the element the reduce function should start with
|
||||||
|
* @param operator that reduces the elements.
|
||||||
|
* @return a new Builder with the reduce function applied
|
||||||
|
*/
|
||||||
|
public <KEY_SPECIAL_TYPE> ASYNC_BUILDER<KEY_SPECIAL_TYPE> reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
return new ASYNC_BUILDERBRACES(new ReduceTaskBRACES(iterable.iterator(), operator, identity));
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* Reduces the elements inside of the Iterable down to one element using a identity element.
|
||||||
|
* @param identity the element the reduce function should start with
|
||||||
|
* @param operator that reduces the elements.
|
||||||
|
* @return a new Builder with the reduce function applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
return new ASYNC_BUILDERBRACES(new ReduceTaskBRACES(iterable.iterator(), operator, identity));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Pours all elements into a List that can be later
|
||||||
|
* @return a new Builder with the pour function applied
|
||||||
|
*/
|
||||||
|
public ObjectAsyncBuilder<LIST KEY_GENERIC_TYPE> pourAsList() {
|
||||||
|
return pour(new ARRAY_LISTBRACES());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* Pours all elements into a Set that can be later
|
||||||
|
* @return a new Builder with the pour function applied
|
||||||
|
*/
|
||||||
|
public ObjectAsyncBuilder<SET KEY_GENERIC_TYPE> pourAsSet() {
|
||||||
|
return pour(new LINKED_HASH_SETBRACES());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Pours all elements into a collection that can be later
|
||||||
|
* @param <E> the return type
|
||||||
|
* @param collection the collection the elements
|
||||||
|
* @return a new Builder with the pour function applied
|
||||||
|
*/
|
||||||
|
public <E extends COLLECTION KEY_GENERIC_TYPE> ObjectAsyncBuilder<E> pour(E collection) {
|
||||||
|
return new ObjectAsyncBuilder<>(new CollectTask<>(iterable.iterator(), collection));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches through the elements of the Iterable to find if the desired element is present.
|
||||||
|
* @param filter that decides the desired elements
|
||||||
|
* @return a new Builder with the matchAny function applied
|
||||||
|
*/
|
||||||
|
public BooleanAsyncBuilder matchAny(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches through the elements of the Iterable to find if unwanted elements are present.
|
||||||
|
* @param filter that decides the unwanted elements
|
||||||
|
* @return a new Builder with the matchNone function applied
|
||||||
|
*/
|
||||||
|
public BooleanAsyncBuilder matchNone(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches through the elements of the Iterable to find if all the desired elements are present.
|
||||||
|
* @param filter that decides the desired elements
|
||||||
|
* @return a new Builder with the matchAll function applied
|
||||||
|
*/
|
||||||
|
public BooleanAsyncBuilder matchAll(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
return new BooleanAsyncBuilder(new MatchTaskBRACES(iterable.iterator(), filter, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches through the elements of the Iterable to find if the desired element.
|
||||||
|
* If not present it will return the default value of the type
|
||||||
|
* @param filter that decides the desired elements
|
||||||
|
* @return self with the findFirst function applied
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
task = new FindFirstTaskBRACES(iterable.iterator(), filter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts all desired elements inside the Iterable
|
||||||
|
* @param filter that decides the desired elements
|
||||||
|
* @return a new Builder with the count function applied
|
||||||
|
*/
|
||||||
|
public IntAsyncBuilder count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
return new IntAsyncBuilder(new CountTaskBRACES(iterable.iterator(), filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional way to add a custom executor that runs this offthread task.
|
||||||
|
* Can only be set after the action was decided on.
|
||||||
|
* @param executor that executes the task, defaults to {@link SanityChecks#invokeAsyncTask(Runnable) }
|
||||||
|
* @return self with the executor set
|
||||||
|
* @note has to be NonNull
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE executor(Executor executor) {
|
||||||
|
if(task == null) throw new IllegalStateException("Action is missing");
|
||||||
|
task.withExecutor(executor);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional way to set a callback that allows to compute actions after the task was completed.
|
||||||
|
* The state of the task has to be validated by the callback.
|
||||||
|
* @param callback that should be notified after completion of the task
|
||||||
|
* @return self with the callback set
|
||||||
|
* @note can be null
|
||||||
|
*/
|
||||||
|
public ASYNC_BUILDER KEY_GENERIC_TYPE onCompletion(Consumer<TASK KEY_GENERIC_TYPE> callback) {
|
||||||
|
if(task == null) throw new IllegalStateException("Action is missing");
|
||||||
|
task.withCallback(callback);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Execution of the task without awaiting its result
|
||||||
|
* @return the task object that allow to trace it.
|
||||||
|
*/
|
||||||
|
public TASK KEY_GENERIC_TYPE execute() {
|
||||||
|
BASE_TASK KEY_GENERIC_TYPE toRun = task;
|
||||||
|
toRun.begin();
|
||||||
|
task = null;
|
||||||
|
return toRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Execution of the task and will await its completion, returning the result.
|
||||||
|
* @return the result of the task provided.
|
||||||
|
* @throws ExecutionException if the task threw a exception
|
||||||
|
* @throws InterruptedException if the caller thread was interrupted
|
||||||
|
*/
|
||||||
|
public KEY_TYPE join() throws ExecutionException, InterruptedException {
|
||||||
|
BASE_TASK KEY_GENERIC_TYPE toRun = task;
|
||||||
|
task = null;
|
||||||
|
toRun.begin();
|
||||||
|
return toRun.GET_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Execution of the task and will await its completion with a timeout, returning the result.
|
||||||
|
* @param timeout of how long the thread should wait the task to be completed
|
||||||
|
* @param unit of the desired waiting time.
|
||||||
|
* @return the result of the provided task
|
||||||
|
* @throws InterruptedException if the caller thread was interrupted
|
||||||
|
* @throws ExecutionException if the task threw a exception
|
||||||
|
* @throws TimeoutException if the timeout was reached before the task was finished
|
||||||
|
*/
|
||||||
|
public KEY_TYPE join(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
BASE_TASK KEY_GENERIC_TYPE toRun = task;
|
||||||
|
task = null;
|
||||||
|
toRun.begin();
|
||||||
|
return toRun.GET_KEY(timeout, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
private static class ReduceTask extends BASE_TASK
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
||||||
|
KEY_TYPE value;
|
||||||
|
|
||||||
|
public ReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator, KEY_TYPE value) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.operator = operator;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
value = operator.apply(value, iter.NEXT());
|
||||||
|
}
|
||||||
|
if(!iter.hasNext()) {
|
||||||
|
setResult(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
operator = null;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
value = null;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
private static class ReduceTask<T, E> extends BaseObjectTask<E>
|
||||||
|
{
|
||||||
|
ObjectIterator<T> iter;
|
||||||
|
BiFunction<E, T, E> operator;
|
||||||
|
E value;
|
||||||
|
|
||||||
|
public ReduceTask(ITERATOR KEY_GENERIC_TYPE iter, BiFunction<E, T, E> operator, E value) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.operator = operator;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
value = operator.apply(value, iter.NEXT());
|
||||||
|
}
|
||||||
|
if(!iter.hasNext()) {
|
||||||
|
setResult(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
operator = null;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
value = null;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
private static class SimpleReduceTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator;
|
||||||
|
boolean first = true;
|
||||||
|
KEY_TYPE value;
|
||||||
|
|
||||||
|
public SimpleReduceTask(ITERATOR KEY_GENERIC_TYPE iter, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
if(first) {
|
||||||
|
first = false;
|
||||||
|
value = iter.NEXT();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value = operator.APPLY_VALUE(value, iter.NEXT());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!iter.hasNext()) {
|
||||||
|
setResult(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
operator = null;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
value = null;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MatchTask KEY_GENERIC_TYPE extends BaseBooleanTask
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
PREDICATE KEY_GENERIC_TYPE filter;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
public MatchTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter, int type) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.filter = filter;
|
||||||
|
this.type = type;
|
||||||
|
if(type < 0 || type > 2) throw new IllegalArgumentException("Type is not allowed has to be between 0-2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
switch(type) {
|
||||||
|
case 0:
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
if(filter.getBoolean(iter.NEXT())) {
|
||||||
|
#else
|
||||||
|
if(filter.GET_VALUE(iter.NEXT())) {
|
||||||
|
#endif
|
||||||
|
setResult(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
if(filter.getBoolean(iter.NEXT())) {
|
||||||
|
#else
|
||||||
|
if(filter.GET_VALUE(iter.NEXT())) {
|
||||||
|
#endif
|
||||||
|
setResult(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
if(!filter.getBoolean(iter.NEXT())) {
|
||||||
|
#else
|
||||||
|
if(!filter.GET_VALUE(iter.NEXT())) {
|
||||||
|
#endif
|
||||||
|
setResult(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!iter.hasNext()) {
|
||||||
|
setResult(type >= 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
filter = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FindFirstTask KEY_GENERIC_TYPE extends BASE_TASK KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
PREDICATE KEY_GENERIC_TYPE filter;
|
||||||
|
|
||||||
|
public FindFirstTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
KEY_TYPE entry = iter.NEXT();
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
if(filter.getBoolean(iter.NEXT())) {
|
||||||
|
#else
|
||||||
|
if(filter.GET_VALUE(iter.NEXT())) {
|
||||||
|
#endif
|
||||||
|
setResult(entry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !iter.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
filter = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CountTask KEY_GENERIC_TYPE extends BaseIntTask
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
PREDICATE KEY_GENERIC_TYPE filter;
|
||||||
|
int counted = 0;
|
||||||
|
|
||||||
|
public CountTask(ITERATOR KEY_GENERIC_TYPE iter, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
if(filter.TEST_VALUE(iter.NEXT())) {
|
||||||
|
counted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!iter.hasNext())
|
||||||
|
{
|
||||||
|
setResult(counted);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
filter = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class CollectTask KSS_GENERIC_TYPE<V, T extends COLLECTION KEY_SPECIAL_GENERIC_TYPE<V>> extends BaseObjectTask<T>
|
||||||
|
{
|
||||||
|
ITERATOR KEY_SPECIAL_GENERIC_TYPE<V> iter;
|
||||||
|
T collection;
|
||||||
|
|
||||||
|
public CollectTask(ITERATOR KEY_SPECIAL_GENERIC_TYPE<V> iter, T collection) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.collection = collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
collection.add(iter.NEXT());
|
||||||
|
}
|
||||||
|
if(!iter.hasNext()) {
|
||||||
|
setResult(collection);
|
||||||
|
collection = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ForEachTask<T> extends BaseObjectTask<Void>
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iter;
|
||||||
|
CONSUMER KEY_GENERIC_TYPE listener;
|
||||||
|
|
||||||
|
public ForEachTask(ITERATOR KEY_GENERIC_TYPE iter, CONSUMER KEY_GENERIC_TYPE listener) {
|
||||||
|
this.iter = iter;
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean execute() throws Exception {
|
||||||
|
while(shouldRun() && iter.hasNext()) {
|
||||||
|
listener.accept(iter.NEXT());
|
||||||
|
}
|
||||||
|
return !iter.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCompletion() {
|
||||||
|
super.onCompletion();
|
||||||
|
iter = null;
|
||||||
|
listener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base Task of the Actions that can be performed.
|
||||||
|
* Allows to simplify the actions that get executed.
|
||||||
|
* @Type(T)
|
||||||
|
*/
|
||||||
|
public abstract static class BASE_TASK KEY_GENERIC_TYPE implements TASK KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
private static final int CREATED = 0;
|
||||||
|
private static final int RUNNING = 1;
|
||||||
|
private static final int PAUSING = 2;
|
||||||
|
private static final int PAUSED = 3;
|
||||||
|
private static final int FINISHING = 4;
|
||||||
|
private static final int FINISHED = 5;
|
||||||
|
private static final int EXCEPTIONALLY = 6;
|
||||||
|
private static final int CANCELLED = 7;
|
||||||
|
private volatile WaitNode waiter;
|
||||||
|
private volatile int state = CREATED;
|
||||||
|
Consumer<TASK KEY_GENERIC_TYPE> callback;
|
||||||
|
Executor executor = SanityChecks::invokeAsyncTask;
|
||||||
|
KEY_TYPE result;
|
||||||
|
Throwable excpetion;
|
||||||
|
|
||||||
|
void withCallback(Consumer<TASK KEY_GENERIC_TYPE> callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void withExecutor(Executor executor) {
|
||||||
|
this.executor = executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
executor.execute(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract boolean execute() throws Exception;
|
||||||
|
|
||||||
|
protected void onCompletion() {
|
||||||
|
if(callback != null) {
|
||||||
|
callback.accept(this);
|
||||||
|
callback = null;
|
||||||
|
}
|
||||||
|
executor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setResult(KEY_TYPE result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
state = RUNNING;
|
||||||
|
try {
|
||||||
|
if(execute()) {
|
||||||
|
state = FINISHING;
|
||||||
|
finishCompletion(FINISHED);
|
||||||
|
}
|
||||||
|
else if(state == PAUSING) {
|
||||||
|
state = PAUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
state = EXCEPTIONALLY;
|
||||||
|
this.excpetion = e;
|
||||||
|
finishCompletion(EXCEPTIONALLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishCompletion(int nextState) {
|
||||||
|
WaitNode current = waiter;
|
||||||
|
waiter = null;
|
||||||
|
while(current != null) {
|
||||||
|
Thread t = current.thread;
|
||||||
|
if (t != null) {
|
||||||
|
current.thread = null;
|
||||||
|
LockSupport.unpark(t);
|
||||||
|
}
|
||||||
|
WaitNode next = current.next;
|
||||||
|
if (next == null)
|
||||||
|
break;
|
||||||
|
current.next = null;
|
||||||
|
current = next;
|
||||||
|
}
|
||||||
|
state = nextState;
|
||||||
|
onCompletion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean cancel(boolean cancelIfRunnning) {
|
||||||
|
if(state == RUNNING && !cancelIfRunnning) return false;
|
||||||
|
state = CANCELLED;
|
||||||
|
finishCompletion(CANCELLED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE GET_KEY() throws InterruptedException, ExecutionException {
|
||||||
|
int s = state;
|
||||||
|
return report(s <= FINISHING ? awaitDone(false, 0L) : s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE GET_KEY(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
if (unit == null) throw new NullPointerException();
|
||||||
|
int s = state;
|
||||||
|
if (s <= FINISHING && (s = awaitDone(true, unit.toNanos(timeout))) <= FINISHING) throw new TimeoutException();
|
||||||
|
return report(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private KEY_TYPE report(int s) throws ExecutionException {
|
||||||
|
if (s == FINISHED) return result;
|
||||||
|
if (s >= CANCELLED) throw new CancellationException();
|
||||||
|
throw new ExecutionException(excpetion);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int awaitDone(boolean timed, long nanos) throws InterruptedException {
|
||||||
|
final long deadline = timed ? System.nanoTime() + nanos : 0L;
|
||||||
|
WaitNode q = null;
|
||||||
|
boolean queued = false;
|
||||||
|
while(true) {
|
||||||
|
if(Thread.interrupted()) {
|
||||||
|
removeWaiter(q);
|
||||||
|
throw new InterruptedException();
|
||||||
|
}
|
||||||
|
int s = state;
|
||||||
|
if(s > FINISHING) {
|
||||||
|
if(q != null) q.thread = null;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
else if(s == FINISHING) Thread.yield();
|
||||||
|
else if(q == null) q = new WaitNode();
|
||||||
|
else if(!queued) {
|
||||||
|
q.next = waiter;
|
||||||
|
waiter = q;
|
||||||
|
queued = true;
|
||||||
|
}
|
||||||
|
else if(timed) {
|
||||||
|
nanos = deadline - System.nanoTime();
|
||||||
|
if(nanos <= 0L) {
|
||||||
|
removeWaiter(q);
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
LockSupport.parkNanos(this, nanos);
|
||||||
|
}
|
||||||
|
else LockSupport.park(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeWaiter(WaitNode node) {
|
||||||
|
if(node == null) return;
|
||||||
|
node.thread = null;
|
||||||
|
retry:
|
||||||
|
while(true) {
|
||||||
|
for(WaitNode prev = null, current = waiter, next = null; current != null; current = next) {
|
||||||
|
next = current.next;
|
||||||
|
if(current.thread != null) prev = current;
|
||||||
|
else if(prev != null) {
|
||||||
|
prev.next = next;
|
||||||
|
if(prev.thread == null) continue retry; //Previous element got removed which means another thread was editing this while we were editing.
|
||||||
|
}
|
||||||
|
else if(waiter == current) {
|
||||||
|
waiter = next;
|
||||||
|
continue retry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() { return state >= CANCELLED; }
|
||||||
|
@Override
|
||||||
|
public boolean isDone() { return state >= FINISHING; }
|
||||||
|
@Override
|
||||||
|
public boolean isPaused() { return state == PAUSED; }
|
||||||
|
@Override
|
||||||
|
public boolean isSuccessful() { return state == FINISHED; }
|
||||||
|
protected boolean shouldRun() { return state == RUNNING; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
if(state == PAUSED || state == PAUSING || state >= FINISHING) return;
|
||||||
|
state = PAUSING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void awaitPausing() {
|
||||||
|
if(state == PAUSED) return;
|
||||||
|
pause();
|
||||||
|
if(state == PAUSING) {
|
||||||
|
while(state == PAUSING) {
|
||||||
|
Thread.yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
if(state != PAUSED && state != PAUSING) return;
|
||||||
|
if(state == PAUSING) {
|
||||||
|
while(state == PAUSING) {
|
||||||
|
Thread.yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state = RUNNING;
|
||||||
|
executor.execute(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class WaitNode {
|
||||||
|
volatile Thread thread;
|
||||||
|
volatile WaitNode next;
|
||||||
|
|
||||||
|
WaitNode() {
|
||||||
|
thread = Thread.currentThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+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(); }
|
||||||
|
|||||||
@@ -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,8 +14,11 @@ 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
|
||||||
@@ -164,6 +169,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
|
||||||
@@ -359,6 +388,42 @@ public class ITERABLES
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|||||||
+67
-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.
|
||||||
@@ -235,6 +237,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 +299,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 +735,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 +745,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 +755,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int previousIndex() {
|
public int previousIndex() {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -761,6 +787,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 +855,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 +891,42 @@ 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 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 +972,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 +1009,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 +1032,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 +1055,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;
|
||||||
@@ -18,6 +20,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SET;
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.EmptyCollection;
|
||||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.SynchronizedCollection;
|
||||||
@@ -33,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
|
||||||
@@ -95,6 +98,29 @@ public class SETS
|
|||||||
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
return s instanceof SynchronizedSortedSet ? s : (s instanceof ITrimmable ? new SynchronizedSortedTrimSetBRACES(s, mutex) : new SynchronizedSortedSetBRACES(s, mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
|
||||||
|
* @param s the set that should be synchronized
|
||||||
|
* @Type(T)
|
||||||
|
* @return a OrderedSet that is synchronized
|
||||||
|
* @note if the set is already synchronized then it will just self return it
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s) {
|
||||||
|
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s) : new SynchronizedOrderedSetBRACES(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Synchronized OrderedSet while preserving the ITrimmable interface
|
||||||
|
* @param s the set that should be synchronized
|
||||||
|
* @param mutex controller for access
|
||||||
|
* @Type(T)
|
||||||
|
* @return a OrderedSet that is synchronized
|
||||||
|
* @note if the set is already synchronized then it will just self return it
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE synchronize(ORDERED_SET KEY_GENERIC_TYPE s, Object mutex) {
|
||||||
|
return s instanceof SynchronizedOrderedSet ? s : (s instanceof ITrimmable ? new SynchronizedOrderedTrimSetBRACES(s, mutex) : new SynchronizedOrderedSetBRACES(s, mutex));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
|
* Creates a Synchronized NavigableSet while preserving the ITrimmable interface
|
||||||
* @param s the set that should be synchronized
|
* @param s the set that should be synchronized
|
||||||
@@ -138,6 +164,16 @@ public class SETS
|
|||||||
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
|
return s instanceof UnmodifiableSortedSet ? s : new UnmodifiableSortedSetBRACES(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Unmodifyable OrderedSet wrapper
|
||||||
|
* @param s OrderedSet that should be made unmodifiable
|
||||||
|
* @Type(T)
|
||||||
|
* @return a UnmodifyableOrderedSet, if the set is already unmodifiable then it returns itself
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ORDERED_SET KEY_GENERIC_TYPE unmodifiable(ORDERED_SET KEY_GENERIC_TYPE s) {
|
||||||
|
return s instanceof UnmodifiableOrderedSet ? s : new UnmodifiableOrderedSetBRACES(s);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates Unmodifyable NavigableSet wrapper
|
* Creates Unmodifyable NavigableSet wrapper
|
||||||
* @param s navigableSet that should be made unmodifiable
|
* @param s navigableSet that should be made unmodifiable
|
||||||
@@ -173,16 +209,19 @@ public class SETS
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator()
|
public ITERATOR KEY_GENERIC_TYPE iterator()
|
||||||
{
|
{
|
||||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||||
boolean next = true;
|
boolean next = true;
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() { return next = false; }
|
public boolean hasNext() { return next; }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!next) throw new IllegalStateException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
next = false;
|
next = false;
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
@@ -200,7 +239,17 @@ public class SETS
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
public boolean remove(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o == this) return true;
|
||||||
|
if(!(o instanceof Set)) return false;
|
||||||
|
return ((Set<?>)o).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||||
}
|
}
|
||||||
@@ -218,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(); }
|
||||||
|
|
||||||
@@ -251,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)); }
|
||||||
@@ -278,6 +340,39 @@ public class SETS
|
|||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class UnmodifiableOrderedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE s;
|
||||||
|
UnmodifiableOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c)
|
||||||
|
{
|
||||||
|
super(c);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
}
|
||||||
|
|
||||||
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
SORTED_SET KEY_GENERIC_TYPE s;
|
SORTED_SET KEY_GENERIC_TYPE s;
|
||||||
@@ -287,48 +382,26 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
}
|
}
|
||||||
@@ -347,6 +420,11 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
public SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
@@ -398,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); } }
|
||||||
|
|
||||||
@@ -489,48 +573,85 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SynchronizedOrderedTrimSet KEY_GENERIC_TYPE extends SynchronizedOrderedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
|
{
|
||||||
|
ITrimmable trim;
|
||||||
|
|
||||||
|
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c) {
|
||||||
|
super(c);
|
||||||
|
trim = (ITrimmable)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
|
super(c, mutex);
|
||||||
|
trim = (ITrimmable)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAndTrim(int size) { synchronized(mutex) { trim.clearAndTrim(size); } }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SynchronizedOrderedSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ORDERED_SET KEY_GENERIC_TYPE s;
|
||||||
|
|
||||||
|
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c) {
|
||||||
|
super(c);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
|
super(c, mutex);
|
||||||
|
s = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||||
|
@Override
|
||||||
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||||
|
@Override
|
||||||
|
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||||
}
|
}
|
||||||
@@ -570,6 +691,11 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o) { synchronized(mutex) { return s.addOrGet(o); } }
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
|
|||||||
+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; }
|
||||||
}
|
}
|
||||||
|
|||||||
+276
-46
@@ -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;
|
||||||
@@ -32,7 +35,10 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
|||||||
#if !TYPE_BOOLEAN
|
#if !TYPE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
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.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;
|
||||||
@@ -41,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;
|
||||||
@@ -56,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
|
||||||
/**
|
/**
|
||||||
@@ -103,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.
|
||||||
@@ -161,6 +169,28 @@ public class MAPS
|
|||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map, mutex); }
|
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedSortedMap ? map : new SynchronizedSortedMapKV_BRACES(map, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function that creates a Helper wrapper to synchronize access into the OrderedMap.
|
||||||
|
* @param map the OrderedMap that should be synchronized
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
* @return a synchronized OrderedMap
|
||||||
|
* @note if the inputted map is already synchronized then it will just return it instead
|
||||||
|
* @note iterators do not support synchronization
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof SynchronizedOrderedMap ? map : new SynchronizedOrderedMapKV_BRACES(map); }
|
||||||
|
/**
|
||||||
|
* Helper function that creates a Helper wrapper to synchronize access with custom access control into the OrderedMap.
|
||||||
|
* @param map the OrderedMap that should be synchronized
|
||||||
|
* @param mutex the object that controls access
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
* @return a synchronized OrderedMap
|
||||||
|
* @note if the inputted map is already synchronized then it will just return it instead
|
||||||
|
* @note iterators do not support synchronization
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) { return map instanceof SynchronizedOrderedMap ? map : new SynchronizedOrderedMapKV_BRACES(map, mutex); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that creates a Helper wrapper to synchronize access into the NavigableMap.
|
* Helper function that creates a Helper wrapper to synchronize access into the NavigableMap.
|
||||||
* @param map the NavigableMap that should be synchronized
|
* @param map the NavigableMap that should be synchronized
|
||||||
@@ -192,6 +222,17 @@ public class MAPS
|
|||||||
* @note if the inputted map is already unmodifiable then it will just return it instead
|
* @note if the inputted map is already unmodifiable then it will just return it instead
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE unmodifiable(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableMap ? map : new UnmodifyableMapKV_BRACES(map); }
|
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE unmodifiable(MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableMap ? map : new UnmodifyableMapKV_BRACES(map); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that creates a Helper wrapper to only allow Read Access into the OrderedMap
|
||||||
|
* @param map the OrderedMap that should be made Unmodifiable
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
* @return a unmodifiable OrderedMap
|
||||||
|
* @note if the inputted OrderedMap is already unmodifiable then it will just return it instead
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableOrderedMap ? map : new UnmodifyableOrderedMapKV_BRACES(map); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function that creates a Helper wrapper to only allow Read Access into the SortedMap
|
* A Helper function that creates a Helper wrapper to only allow Read Access into the SortedMap
|
||||||
* @param map the SortedMap that should be made Unmodifiable
|
* @param map the SortedMap that should be made Unmodifiable
|
||||||
@@ -201,6 +242,7 @@ public class MAPS
|
|||||||
* @note if the inputted SortedMap is already unmodifiable then it will just return it instead
|
* @note if the inputted SortedMap is already unmodifiable then it will just return it instead
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableSortedMap ? map : new UnmodifyableSortedMapKV_BRACES(map); }
|
public static GENERIC_KEY_VALUE_BRACES SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableSortedMap ? map : new UnmodifyableSortedMapKV_BRACES(map); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper function that creates a Helper wrapper to only allow Read Access into NavigableMap Map
|
* A Helper function that creates a Helper wrapper to only allow Read Access into NavigableMap Map
|
||||||
* @param map the NavigableMap that should be made Unmodifiable
|
* @param map the NavigableMap that should be made Unmodifiable
|
||||||
@@ -210,6 +252,7 @@ public class MAPS
|
|||||||
* @note if the inputted NavigableMap is already unmodifiable then it will just return it instead
|
* @note if the inputted NavigableMap is already unmodifiable then it will just return it instead
|
||||||
*/
|
*/
|
||||||
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableNavigableMap ? map : new UnmodifyableNavigableMapKV_BRACES(map); }
|
public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable(NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map) { return map instanceof UnmodifyableNavigableMap ? map : new UnmodifyableNavigableMapKV_BRACES(map); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@@ -217,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
|
||||||
@@ -225,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.
|
||||||
@@ -262,6 +305,8 @@ public class MAPS
|
|||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
@@ -277,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
|
||||||
@@ -310,6 +367,8 @@ public class MAPS
|
|||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
@@ -323,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
|
||||||
@@ -368,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()); }
|
||||||
@@ -420,18 +493,18 @@ 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(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function
|
* The Unmodifyable Ordered Map implementation that is sued for the unmodifyableMap function
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
* @ValueType(V)
|
* @ValueType(V)
|
||||||
*/
|
*/
|
||||||
public static class UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE {
|
public static class UnmodifyableOrderedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||||
SORTED_MAP KEY_VALUE_GENERIC_TYPE map;
|
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||||
|
|
||||||
UnmodifyableSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
UnmodifyableOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
super(map);
|
super(map);
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
@@ -448,6 +521,46 @@ public class MAPS
|
|||||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||||
|
@Override
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Unmodifyable Sorted Map implementation that is sued for the unmodifyableMap function
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public static class UnmodifyableSortedMap KEY_VALUE_GENERIC_TYPE extends UnmodifyableMap KEY_VALUE_GENERIC_TYPE implements SORTED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||||
|
SORTED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||||
|
|
||||||
|
UnmodifyableSortedMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
|
super(map);
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -457,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(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,6 +609,8 @@ public class MAPS
|
|||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
@@ -504,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() {
|
||||||
@@ -531,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)
|
||||||
@@ -589,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
|
||||||
@@ -625,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); } }
|
||||||
@@ -680,6 +859,63 @@ public class MAPS
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Synchronized Ordered Map implementation used by the synchronizedMap helper function
|
||||||
|
* @Type(T)
|
||||||
|
* @ValueType(V)
|
||||||
|
*/
|
||||||
|
public static class SynchronizedOrderedMap KEY_VALUE_GENERIC_TYPE extends SynchronizedMap KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||||
|
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||||
|
|
||||||
|
SynchronizedOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
|
super(map);
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedOrderedMap(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map, Object mutex) {
|
||||||
|
super(map, mutex);
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
||||||
|
@Override
|
||||||
|
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE FIRST_ENTRY_KEY() { synchronized(mutex) { return map.FIRST_ENTRY_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_FIRST_ENTRY_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE LAST_ENTRY_KEY() { synchronized(mutex) { return map.LAST_ENTRY_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() { synchronized(mutex) { return map.POLL_LAST_ENTRY_KEY(); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE FIRST_ENTRY_VALUE() { synchronized(mutex) { return map.FIRST_ENTRY_VALUE(); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||||
|
@Override
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Synchronized Sorted Map implementation used by the synchronizedMap helper function
|
* The Synchronized Sorted Map implementation used by the synchronizedMap helper function
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -698,18 +934,6 @@ public class MAPS
|
|||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
|
|
||||||
@Override
|
|
||||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
|
||||||
@Override
|
|
||||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
|
|
||||||
@Override
|
|
||||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } }
|
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } }
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -719,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(); } }
|
||||||
@@ -731,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
|
||||||
@@ -791,6 +1017,8 @@ public class MAPS
|
|||||||
#if VALUE_PRIMITIVES
|
#if VALUE_PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.addTo(key, value); } }
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.addTo(key, value); } }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.subFrom(key, value); } }
|
||||||
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m) { synchronized(mutex) { map.addToAll(m); } }
|
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m) { synchronized(mutex) { map.addToAll(m); } }
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
@@ -833,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); } }
|
||||||
@@ -843,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);
|
||||||
|
|||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
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_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_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
|
||||||
|
}
|
||||||
+200
@@ -0,0 +1,200 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl.maps;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.Objects;
|
||||||
|
#endif
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.CONCURRENT_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||||
|
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||||
|
#if TYPE_OBJECT || VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.objects.lists.ObjectList;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR;
|
||||||
|
import speiger.src.testers.objects.utils.ObjectSamples;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE<E extends MAP KEY_VALUE_GENERIC_TYPE>
|
||||||
|
{
|
||||||
|
BiFunction<KEY_TYPE[], VALUE_TYPE[], E> mapper;
|
||||||
|
#if TYPE_BYTE
|
||||||
|
KEY_TYPE[] keys = new KEY_TYPE[]{(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)-2, (byte)-1, (byte)5, (byte)6};
|
||||||
|
#else if TYPE_SHORT
|
||||||
|
KEY_TYPE[] keys = new KEY_TYPE[]{(short)0, (short)1, (short)2, (short)3, (short)4, (short)-2, (short)-1, (short)5, (short)6};
|
||||||
|
#else if TYPE_CHAR
|
||||||
|
KEY_TYPE[] keys = new KEY_TYPE[]{(char)0, (char)1, (char)2, (char)3, (char)4};
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
KEY_TYPE[] keys;
|
||||||
|
#else
|
||||||
|
KEY_TYPE[] keys = new KEY_TYPE[]{0, 1, 2, 3, 4, -2, -1, 5, 6};
|
||||||
|
#endif
|
||||||
|
#if VALUE_BOOLEAN
|
||||||
|
VALUE_TYPE[] values = new VALUE_TYPE[]{true, true, true, false, true, false, true, false, true};
|
||||||
|
#else if VALUE_BYTE
|
||||||
|
VALUE_TYPE[] values = new VALUE_TYPE[]{(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)-2, (byte)-1, (byte)5, (byte)6};
|
||||||
|
#else if VALUE_SHORT
|
||||||
|
VALUE_TYPE[] values = new VALUE_TYPE[]{(short)0, (short)1, (short)2, (short)3, (short)4, (short)-2, (short)-1, (short)5, (short)6};
|
||||||
|
#else if VALUE_CHAR
|
||||||
|
VALUE_TYPE[] values = new VALUE_TYPE[]{(char)0, (char)1, (char)2, (char)3, (char)4};
|
||||||
|
#else if VALUE_OBJECT
|
||||||
|
VALUE_TYPE[] values;
|
||||||
|
#else
|
||||||
|
VALUE_TYPE[] values = new VALUE_TYPE[]{0, 1, 2, 3, 4, -2, -1, 5, 6};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public SIMPLE_MAP_TEST_GENERATOR(BiFunction<KEY_TYPE[], VALUE_TYPE[], E> mapper) {
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT || TYPE_CHAR
|
||||||
|
public void setKeys(KEY_TYPE... keys) {
|
||||||
|
this.keys = keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT || VALUE_CHAR
|
||||||
|
public void setValues(VALUE_TYPE... values) {
|
||||||
|
this.values = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
public ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE> getSamples() {
|
||||||
|
return new ObjectSamples<MAP.Entry KEY_VALUE_GENERIC_TYPE>(
|
||||||
|
new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[0], values[0]),
|
||||||
|
new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[1], values[1]),
|
||||||
|
new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[2], values[2]),
|
||||||
|
new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[3], values[3]),
|
||||||
|
new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[4], values[4])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public E create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
KEY_TYPE[] keys = (T[])ObjectArrays.newArray(getSamples().e0().ENTRY_KEY().getClass(), elements.length);
|
||||||
|
#else
|
||||||
|
KEY_TYPE[] keys = NEW_KEY_ARRAY(elements.length);
|
||||||
|
#endif
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
VALUE_TYPE[] values = (V[])ObjectArrays.newArray(getSamples().e0().ENTRY_VALUE().getClass(), elements.length);
|
||||||
|
#else
|
||||||
|
VALUE_TYPE[] values = NEW_VALUE_ARRAY(elements.length);
|
||||||
|
#endif
|
||||||
|
for(int i = 0;i<elements.length;i++) {
|
||||||
|
keys[i] = elements[i].ENTRY_KEY();
|
||||||
|
values[i] = elements[i].ENTRY_VALUE();
|
||||||
|
}
|
||||||
|
return mapper.apply(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> order(List<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Maps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE<MAP KEY_VALUE_GENERIC_TYPE> implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public Maps(BiFunction<KEY_TYPE[], VALUE_TYPE[], MAP KEY_VALUE_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OrderedMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE<ORDERED_MAP KEY_VALUE_GENERIC_TYPE> implements TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public OrderedMaps(BiFunction<KEY_TYPE[], VALUE_TYPE[], ORDERED_MAP KEY_VALUE_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ConcurrentMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE<CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE> implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
Consumer<ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE>> sorter;
|
||||||
|
|
||||||
|
public ConcurrentMaps(BiFunction<KEY_TYPE[], VALUE_TYPE[], CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE> mapper, Consumer<ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE>> sorter) {
|
||||||
|
super(mapper);
|
||||||
|
this.sorter = sorter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> order(List<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> insertionOrder) {
|
||||||
|
ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> newList = new ObjectArrayList<>();
|
||||||
|
for(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry : insertionOrder) {
|
||||||
|
newList.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(entry.getKey(), entry.getValue()));
|
||||||
|
}
|
||||||
|
order(newList);
|
||||||
|
insertionOrder.sort(new Comparator<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> key, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> value) {
|
||||||
|
return Integer.signum(indexOf(OBJ_TO_KEY(key.getKey())) - indexOf(OBJ_TO_KEY(value.getKey())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int indexOf(KEY_TYPE key) {
|
||||||
|
for(int i = 0,m=newList.size();i<m;i++) {
|
||||||
|
if(KEY_EQUALS(newList.get(i).ENTRY_KEY(), key)) return i;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("MAP.entry sorter was corrupting data");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
sorter.accept(insertionOrder);
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SortedMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE<SORTED_MAP KEY_VALUE_GENERIC_TYPE> implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
public SortedMaps(BiFunction<KEY_TYPE[], VALUE_TYPE[], SORTED_MAP KEY_VALUE_GENERIC_TYPE> mapper) {
|
||||||
|
super(mapper);
|
||||||
|
#if TYPE_CHAR
|
||||||
|
setKeys(new KEY_TYPE[]{'a', 'b', 'c', 'd', 'e', '_', '`', 'f', 'g'});
|
||||||
|
#endif
|
||||||
|
#if VALUE_CHAR
|
||||||
|
setValues(new VALUE_TYPE[]{'a', 'b', 'c', 'd', 'e', '_', '`', 'f', 'g'});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> order(List<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> insertionOrder) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
insertionOrder.sort(DERIVED_MAP_GENERATORS.entryObjectComparator((Comparator<T>)Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
insertionOrder.sort(DERIVED_MAP_GENERATORS.entryObjectComparator(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectIterable<MAP.Entry KEY_VALUE_GENERIC_TYPE> order(ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> insertionOrder) {
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
insertionOrder.sort(DERIVED_MAP_GENERATORS.entryComparator((Comparator<T>)Comparator.naturalOrder()));
|
||||||
|
#else
|
||||||
|
insertionOrder.sort(DERIVED_MAP_GENERATORS.entryComparator(CLASS_TYPE::compare));
|
||||||
|
#endif
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[5], values[5]); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[6], values[6]); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[7], values[7]); }
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[8], values[8]); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.impl.maps;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||||
|
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
||||||
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectSet;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class SIMPLE_TEST_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
MAP KEY_VALUE_GENERIC_TYPE map;
|
||||||
|
|
||||||
|
public SIMPLE_TEST_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) {
|
||||||
|
map = new ARRAY_MAPKV_BRACES(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v) {
|
||||||
|
map.setDefaultReturnValue(v);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { return map.put(key, value); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { return map.putIfAbsent(key, value); }
|
||||||
|
#if VALUE_PRIMITIVES
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { return map.addTo(key, value); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { return map.subFrom(key, value); }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { return map.REMOVE_VALUE(key); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.REMOVE_VALUEOrDefault(key, defaultValue); }
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { return map.remove(key, value); }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE remove(Object key) { return map.remove(key); }
|
||||||
|
@Override
|
||||||
|
public boolean remove(Object key, Object value) { return map.remove(key, value); }
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
||||||
|
#if TYPE_OBJECT && !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||||
|
return new AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>() {
|
||||||
|
@Override
|
||||||
|
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||||
|
return new ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>() {
|
||||||
|
ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iter = map.ENTRY_SET().iterator();
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return iter.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next();
|
||||||
|
return new ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC_TYPE(entry.ENTRY_KEY(), entry.ENTRY_VALUE()) {
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||||
|
return entry.setValue(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return map.size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.tests.base;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE extends ABSTRACT_CONTAINER_TESTER KKS_GENERIC_TYPE<COLLECTION KEY_CLASS_GENERIC_TYPE>
|
||||||
|
{
|
||||||
|
protected COLLECTION KEY_GENERIC_TYPE collection;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected COLLECTION KEY_GENERIC_TYPE actualContents() {
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected COLLECTION KEY_GENERIC_TYPE resetContainer(COLLECTION KEY_GENERIC_TYPE newContents) {
|
||||||
|
collection = super.resetContainer(newContents);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void resetCollection() {
|
||||||
|
resetContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+188
@@ -0,0 +1,188 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.tests.base;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AbstractTester;
|
||||||
|
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.TestContainerGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||||
|
import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.HELPERS;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||||
|
import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class ABSTRACT_CONTAINER_TESTER KKS_GENERIC_TYPE<E> extends AbstractTester<OneSizeTestContainerGenerator<E, CLASS_TYPE>>
|
||||||
|
{
|
||||||
|
protected SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples;
|
||||||
|
protected E container;
|
||||||
|
protected TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE primitiveGenerator;
|
||||||
|
protected CollectionSize size;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@OverridingMethodsMustInvokeSuper
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
setupGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setupGenerator() {
|
||||||
|
TestContainerGenerator<E, CLASS_TYPE> generator = getSubjectGenerator().getInnerGenerator();
|
||||||
|
if (!(generator instanceof TEST_COLLECTION_GENERATOR)) throw new IllegalStateException("Test Generator Must extend TEST_COLLECTION_GENERATOR");
|
||||||
|
primitiveGenerator = (TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE) generator;
|
||||||
|
samples = primitiveGenerator.getSamples();
|
||||||
|
size = getSubjectGenerator().getCollectionSize();
|
||||||
|
resetContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract COLLECTION KEY_GENERIC_TYPE actualContents();
|
||||||
|
|
||||||
|
protected E resetContainer() {
|
||||||
|
return resetContainer(createTestSubject());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected E resetContainer(E newValue) {
|
||||||
|
container = newValue;
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void expectContents(KEY_TYPE... elements) {
|
||||||
|
expectContents(ARRAY_LIST.wrap(elements));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void expectContents(COLLECTION KEY_GENERIC_TYPE expected) {
|
||||||
|
HELPERS.assertEqualIgnoringOrder(expected, actualContents());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void expectUnchanged() {
|
||||||
|
expectContents(getOrderedElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void expectAdded(KEY_TYPE... elements) {
|
||||||
|
LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(getSampleElements());
|
||||||
|
expected.addAll(elements);
|
||||||
|
expectContents(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void expectAddedIndex(int index, KEY_TYPE... elements) {
|
||||||
|
expectAdded(index, ARRAY_LIST.wrap(elements));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void expectAdded(int index, COLLECTION KEY_GENERIC_TYPE elements) {
|
||||||
|
LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(getSampleElements());
|
||||||
|
expected.addAll(index, elements);
|
||||||
|
expectContents(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void expectMissing(KEY_TYPE... elements) {
|
||||||
|
for (KEY_TYPE element : elements) {
|
||||||
|
assertFalse("Should not contain " + element, actualContents().contains(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected KEY_TYPE[] createSamplesArray() {
|
||||||
|
return getSampleElements().TO_ARRAY(NEW_KEY_ARRAY(getNumElements()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected KEY_TYPE[] createOrderedArray() {
|
||||||
|
return getOrderedElements().TO_ARRAY(NEW_KEY_ARRAY(getNumElements()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ArrayWithDuplicate KEY_GENERIC_TYPE {
|
||||||
|
public final KEY_TYPE[] elements;
|
||||||
|
public final KEY_TYPE duplicate;
|
||||||
|
|
||||||
|
private ArrayWithDuplicate(KEY_TYPE[] elements, KEY_TYPE duplicate) {
|
||||||
|
this.elements = elements;
|
||||||
|
this.duplicate = duplicate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayWithDuplicate KEY_GENERIC_TYPE createArrayWithDuplicateElement() {
|
||||||
|
KEY_TYPE[] elements = createSamplesArray();
|
||||||
|
KEY_TYPE duplicate = elements[(elements.length / 2) - 1];
|
||||||
|
elements[(elements.length / 2) + 1] = duplicate;
|
||||||
|
return new ArrayWithDuplicateBRACES(elements, duplicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getNumElements() {
|
||||||
|
return size.getNumElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected COLLECTION KEY_GENERIC_TYPE getSampleElements() {
|
||||||
|
return getSampleElements(getNumElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected LIST KEY_GENERIC_TYPE getOrderedElements() {
|
||||||
|
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||||
|
for (ITERATOR KEY_GENERIC_TYPE iter = primitiveGenerator.order(new ARRAY_LISTBRACES(getSampleElements())).iterator(); iter.hasNext();) {
|
||||||
|
list.add(iter.NEXT());
|
||||||
|
}
|
||||||
|
return LISTS.unmodifiable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
protected KEY_TYPE[] createDisjointArray() {
|
||||||
|
KEY_TYPE[] array = NEW_KEY_ARRAY(2);
|
||||||
|
array[0] = e3();
|
||||||
|
array[1] = e4();
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
protected KEY_TYPE[] createDisjointArray() {
|
||||||
|
return new KEY_TYPE[]{e3(), e4()};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
protected KEY_TYPE[] emptyArray() {
|
||||||
|
return NEW_KEY_ARRAY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MINIMAL_COLLECTION KEY_GENERIC_TYPE createDisjointCollection() {
|
||||||
|
return MINIMAL_COLLECTION.of(e3(), e4());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MINIMAL_COLLECTION KEY_GENERIC_TYPE emptyCollection() {
|
||||||
|
return MINIMAL_COLLECTION.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE[] createArray(KEY_TYPE...array) {
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final KEY_TYPE e0() {
|
||||||
|
return samples.e0();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final KEY_TYPE e1() {
|
||||||
|
return samples.e1();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final KEY_TYPE e2() {
|
||||||
|
return samples.e2();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final KEY_TYPE e3() {
|
||||||
|
return samples.e3();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final KEY_TYPE e4() {
|
||||||
|
return samples.e4();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected E createTestSubject() {
|
||||||
|
return (E)primitiveGenerator.create(getSampleElements(size.getNumElements()).TO_ARRAY(NEW_KEY_ARRAY(getNumElements())));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected COLLECTION KEY_GENERIC_TYPE getSampleElements(int howMany) {
|
||||||
|
return new ARRAY_LISTBRACES(samples.asList().subList(0, howMany));
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package speiger.src.testers.PACKAGE.tests.base;
|
||||||
|
|
||||||
|
#ignore
|
||||||
|
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||||
|
#endignore
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class ABSTRACT_LIST_INDEX_OF_TESTER KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
protected abstract int find(KEY_TYPE o);
|
||||||
|
|
||||||
|
protected abstract String getMethodName();
|
||||||
|
|
||||||
|
@CollectionSize.Require(absent = ZERO)
|
||||||
|
public void testFind_yes() {
|
||||||
|
assertEquals(getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().GET_KEY(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFind_no() {
|
||||||
|
assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user