Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddc58ee221 | ||
|
|
8b5e5a75c1 | ||
|
|
c1862e6b05 | ||
|
|
c2c2780967 | ||
|
|
086d933a0d | ||
|
|
1e7da394a1 | ||
|
|
9eb220194f | ||
|
|
0baf141e4b | ||
|
|
569d4f5c86 | ||
|
|
36f24731b0 | ||
|
|
ea5ace0166 | ||
|
|
663809ff27 | ||
|
|
5d6adb5446 | ||
|
|
212ad1ace2 | ||
|
|
707827929a | ||
|
|
27ad01657d | ||
|
|
e7da7acc08 | ||
|
|
72943cb22c | ||
|
|
068cc4a4f7 | ||
|
|
31b34f5de1 | ||
|
|
4bded1af80 | ||
|
|
100c7fe260 | ||
|
|
04f628fcc1 | ||
|
|
5fa26bfbf3 | ||
|
|
4d3eaaf604 | ||
|
|
33ab7c48bf | ||
|
|
1f4784c75e | ||
|
|
ae5a4ea818 | ||
|
|
5d66f7b453 | ||
|
|
12af656150 | ||
|
|
603ff3df0f | ||
|
|
b712981718 | ||
|
|
863d1a1027 | ||
|
|
6287da8efe | ||
|
|
c27e852ccb | ||
|
|
0157765628 | ||
|
|
8689037ceb | ||
|
|
03a8914986 | ||
|
|
26b9d6706d | ||
|
|
a21d4a9eb6 | ||
|
|
212d614ebd | ||
|
|
bcba3ccde0 | ||
|
|
b42ad76372 | ||
|
|
f95565771a | ||
|
|
3d6cbf5ac1 | ||
|
|
fc5d43e14b | ||
|
|
b3264748cd | ||
|
|
ede40f06d0 | ||
|
|
e69c675f82 | ||
|
|
17c1c90957 | ||
|
|
c6f2f71f6c | ||
|
|
d2c7c151bc | ||
|
|
4448eca787 | ||
|
|
0350a77dff | ||
|
|
4f98c599df | ||
|
|
103b2407d2 | ||
|
|
059da9be12 | ||
|
|
3cac3a997e | ||
|
|
3ffb001c73 | ||
|
|
2810a6f952 | ||
|
|
166362334b | ||
|
|
d3f9103ebf | ||
|
|
1c5507d4a5 | ||
|
|
5e3cd9f484 | ||
|
|
f27b884b6a | ||
|
|
769a9d8ea5 | ||
|
|
9499a7f0e0 | ||
|
|
ca38583f96 | ||
|
|
9557a0cfb5 | ||
|
|
c61e8bb7fc | ||
|
|
4fbcaa47f8 | ||
|
|
6f31fc5abb | ||
|
|
10ec0e35d0 | ||
|
|
29c4d253cf | ||
|
|
55c870d392 | ||
|
|
cda6ec066d | ||
|
|
c8b89e6847 | ||
|
|
b46a739008 | ||
|
|
af62394651 | ||
|
|
bc75a5cd97 | ||
|
|
7d8af3af08 | ||
|
|
ef8197b275 | ||
|
|
58d9ac7fdd | ||
|
|
86a893916d | ||
|
|
e7a6292fe9 | ||
|
|
81209b0cf8 | ||
|
|
77b8147f9b | ||
|
|
32abd7e14e | ||
|
|
8a582f0b08 | ||
|
|
01be6f7d43 | ||
|
|
9011700879 | ||
|
|
12cd4e5e5f | ||
|
|
10201bcadb | ||
|
|
3b4fcc0069 | ||
|
|
31a1ef74fb | ||
|
|
9be3a1475f | ||
|
|
7591f396fd | ||
|
|
517b84042f | ||
|
|
dbfae33074 | ||
|
|
ead34009c6 | ||
|
|
7a4a0f05d1 | ||
|
|
8f32b2d887 | ||
|
|
e6c9600b40 | ||
|
|
d5f2acb9ab | ||
|
|
3274e96355 | ||
|
|
78dfa286b0 | ||
|
|
f32624d131 | ||
|
|
59a417056c | ||
|
|
18f6704ed7 | ||
|
|
caf2f22e9f | ||
|
|
865966db55 | ||
|
|
6266a6293c | ||
|
|
70ea60aacf | ||
|
|
599cc44fff | ||
|
|
e1df59d512 | ||
|
|
eaa45976c7 | ||
|
|
362838c434 | ||
|
|
52caa9cdd2 | ||
|
|
c6afdb8762 | ||
|
|
c4964806f0 | ||
|
|
a2506b927a | ||
|
|
53061d9f78 | ||
|
|
2555dc7fc2 | ||
|
|
058087e15a | ||
|
|
c20c6393e5 | ||
|
|
a25ec85ba2 | ||
|
|
c930bda7a6 | ||
|
|
e7bc242292 | ||
|
|
b90a9ec7d8 | ||
|
|
d18a35d9b7 |
@@ -0,0 +1,36 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
|
||||||
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||||
|
|
||||||
|
name: Latest Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
jdk: [8, 11, 14, 16, 17]
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up JDK ${{ matrix.jdk }}
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: ${{ matrix.jdk }}
|
||||||
|
- name: Validate Gradle wrapper
|
||||||
|
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
||||||
|
- name: Make gradlew executable
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew build
|
||||||
@@ -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
|
||||||
|
|||||||
+138
@@ -1,5 +1,143 @@
|
|||||||
# 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
|
||||||
|
- Added: 2 Helper functions to find out how many bits are required to store a Number.
|
||||||
|
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
|
||||||
|
- Added: The new ToArray method from Java9 and newer into the library. Using a functional interface. (Just a backport)
|
||||||
|
- Changed: Reworked how the Map Builder functions are created. They are now in a SubClass that moves them out of the way. Less Clutter. (This might break things if that was used before)
|
||||||
|
- Added: Map Builder that allows now to Build Maps like Guava ImmutableMaps can be build. Note: This has a slight performance overhead.
|
||||||
|
- Added: Unmodifiable and Synchronize wrapper functions direclty into Collection Interfaces. This is mostly a quality of life thing.
|
||||||
|
- Added: Unmodifiable and Synchronized Wrapper Collections can now be cloned. They clone the underlying map which doesn't break functionality. (Had a usecase for it)
|
||||||
|
- Added: A boxed putAll array variant.
|
||||||
|
- Fixed: EnumMaps didn't keep track of their size and now got proper care and implementations as needed. There might be more work required but at least the core functionality is now up to date.
|
||||||
|
- Added: Tests for the new Stream replace functions to ensure no bugs are left.
|
||||||
|
- Fixed: Custom HashSet reduce function with a default value was checking incorrectly for present keys.
|
||||||
|
- Added: Guava TestSuit
|
||||||
|
- Fixed: HashCode and toString method would crash if the Object Key/Value was null
|
||||||
|
- Added: AbstractTypeCollection now delegates the contains check to type-specific Collections if it detects it.
|
||||||
|
- Fixed: Map.Entry toString wasn't writing values not like it should do.
|
||||||
|
- Fixed: Set.hashCode now is the sum of the elements instead of a Unique HashCode based on the elements.
|
||||||
|
- Fixed: Added missing NonNull Checks.
|
||||||
|
- Fixed: Custom/OpenHashMap.containsValue implementation was wrong.
|
||||||
|
- Fixed: Custom/OpenHashMap.compute/present/absent now works how it is specified in the Java Documentation
|
||||||
|
- Fixed: Custom/OpenHashMap.merge/BulkMerge now works how it is specified in the Java Documentation
|
||||||
|
- Fixed: Custom/Linked/OpenHashMap.keySet.remove was causing a infinite loop.
|
||||||
|
- Fixed: Custom/Linked/OpenHashMap.entrySet.contains was not correctly comparing the entry.
|
||||||
|
- Fixed: Custom/OpenHashMap.mapIterator now no longer crashes in certain cases.
|
||||||
|
- Added: Custom/LinkedOpenHashMap now takes use of the improved Iterator it has for containsValue
|
||||||
|
- Fixed: CustomOpenHashMap.keySet.forEach was basically putting out keys even if they were present
|
||||||
|
- Fixed: ImmutableMaps issues thanks to the tests. Roughly the same as the rest of the maps
|
||||||
|
- Fixed: RB/AVLTreeMaps issues. Roughly the same as the rest of the maps
|
||||||
|
- Fixed: SubLists are now properly implemented.
|
||||||
|
- Fixed: HashSet Iterator bugs now fixed... That was Painful.
|
||||||
|
- Added: Tests for Lists and Sets
|
||||||
|
|
||||||
|
### Version 0.4.5
|
||||||
|
- Added: removeAll/retainAll(Collection c, Consumer r) which receives all the elements that got deleted from the collection
|
||||||
|
- Fixed: Supplier get function wasn't referencing original function.
|
||||||
|
- Added: addIfPresent/Absent to lists
|
||||||
|
- Added: distinct, limit and peek iterators
|
||||||
|
- Added: Iterable's can now reduce its contents
|
||||||
|
- Added: Better ForEach support for IterableWrappers so a Iterator chain is not created
|
||||||
|
- Added: SwapRemove to Lists which moves the last element into the desired space to be deleted
|
||||||
|
- Added: More Test cases
|
||||||
|
|
||||||
### Version 0.4.4
|
### Version 0.4.4
|
||||||
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
- Fixed: ObjectArrayList.of was causing crashes because of a Poor implementation.
|
||||||
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
- Added: Unsorted HashMaps/Sets now throw Concurrent exceptions if they were modified during a rehash.
|
||||||
|
|||||||
@@ -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,93 +1,56 @@
|
|||||||
|

|
||||||
|
[](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
|
||||||
- Streams
|
- Priority Queues
|
||||||
- SplitIterators
|
- Streams & Functional Queries
|
||||||
- Iterators
|
- Split/Iterators
|
||||||
- Pairs
|
- Pairs
|
||||||
- Unary/Functions
|
- Unary/Functions
|
||||||
- Suppliers
|
- Suppliers
|
||||||
- Bi/Consumers
|
- Bi/Consumers
|
||||||
|
- AsyncBuilders
|
||||||
## Specialized Functions
|
|
||||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
|
||||||
To highlight things that may be wanted.
|
|
||||||
- Iterable:
|
|
||||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
|
||||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
|
||||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
|
||||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
|
||||||
- count: counts all valid elements in a collection.
|
|
||||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
|
||||||
- Collection:
|
|
||||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
|
||||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
|
||||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
|
||||||
(subCollections/synchronized/unmodifiable not supported for obvious reasons)
|
|
||||||
- List:
|
|
||||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
|
||||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
|
||||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
|
||||||
- SortedSet:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
|
||||||
- pollFirst/Last: Allows to poll the first/last element of the set.
|
|
||||||
- Map:
|
|
||||||
- putAll: putAll but in Array form.
|
|
||||||
- putAllIfAbsent: Puts only the elements that are absent.
|
|
||||||
- addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
|
|
||||||
- addToAll: Same as addTo but bulkVersion.
|
|
||||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
|
||||||
- mergeAll: BulkVersion of Merge function.
|
|
||||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
|
||||||
- Sorted Map:
|
|
||||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
|
||||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
|
||||||
- getAndMoveToFirst/Last: gets the element and moves it to the first/last position. Replicating a Optional LinkedHashMap feature.
|
|
||||||
- pollFirst/LastKey: Allows to poll the first/last element.
|
|
||||||
- first/LastValue: Allows to get the first/last value from the Map.
|
|
||||||
|
|
||||||
|
|
||||||
# Notes about Versions
|
# Notes about Versions
|
||||||
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||||
Any breaking changes will be Documented (once 1.0 is released)
|
|
||||||
|
|
||||||
# How to install
|
# How to install
|
||||||
Using Gradle:
|
Using Jitpack Gradle
|
||||||
```gradle
|
```gradle
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.speiger.com/repository/main"
|
url = "https://jitpack.io"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'de.speiger:Primitive-Collections:0.4.4'
|
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Direct:
|
|
||||||
|
|
||||||
| Version | Jar | Sources | Java Doc |
|
# SourceCode
|
||||||
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
|
The generated Sourcecode can be automatically build,
|
||||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
but if you want to just browse around in it.
|
||||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
Check out the [Debug Branch](https://github.com/Speiger/Primitive-Collections/tree/debug/src/main/java/speiger/src/collections), which has the entire up to date code.
|
||||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
|
||||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
|
||||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
|
||||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
|
||||||
| 0.3.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.5/Primitive-Collections-0.3.5-javadoc.jar) |
|
|
||||||
| 0.3.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.4/Primitive-Collections-0.3.4-javadoc.jar) |
|
|
||||||
| 0.3.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.3/Primitive-Collections-0.3.3-javadoc.jar) |
|
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
If you want to contribute.
|
If you want to contribute.
|
||||||
@@ -107,10 +70,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)
|
|
||||||
- Testing for Sub Maps/Sets/Lists are only in a very basic way tested
|
|
||||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
|
||||||
+46
-14
@@ -8,7 +8,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 +18,11 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.4.4';
|
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,9 +44,10 @@ 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'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task generateSource(type: JavaExec) {
|
task generateSource(type: JavaExec) {
|
||||||
@@ -54,6 +57,14 @@ 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 = ['false', 'true']
|
||||||
|
}
|
||||||
|
|
||||||
task forceGenerateSource(type: JavaExec) {
|
task forceGenerateSource(type: JavaExec) {
|
||||||
group = 'internal'
|
group = 'internal'
|
||||||
description = 'Builds the sourcecode forceful'
|
description = 'Builds the sourcecode forceful'
|
||||||
@@ -72,6 +83,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()
|
||||||
@@ -85,19 +98,23 @@ test {
|
|||||||
useJUnit()
|
useJUnit()
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadArchives {
|
publishing {
|
||||||
repositories.mavenDeployer {
|
Properties props = new Properties()
|
||||||
repository(url: 'https://maven.speiger.com/repository/main') {
|
if(file("$buildDir/credentials.properties").exists()) {
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
props.load(new FileInputStream("$buildDir/credentials.properties"))
|
||||||
}
|
|
||||||
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
|
||||||
authentication(userName: project.properties.mavenUser, password: project.properties.mavenPassword)
|
|
||||||
}
|
}
|
||||||
|
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'
|
||||||
@@ -108,9 +125,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
|
||||||
|
|
||||||
@@ -75,6 +75,7 @@ public class GlobalVariables
|
|||||||
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
addSimpleMapper(" GENERIC_VALUE_BRACES", valueType.isObject() ? " <"+valueType.getValueType()+">" : "");
|
||||||
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
addInjectMapper(" GENERIC_SPECIAL_KEY_BRACES", type.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||||
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
addInjectMapper(" GENERIC_SPECIAL_VALUE_BRACES", valueType.isObject() ? " <%s>" : "").removeBraces().setBraceType("<>");
|
||||||
|
addSimpleMapper(" GENERIC_KEY_ENUM_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : " <"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : ""));
|
||||||
|
|
||||||
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
addInjectMapper(" GENERIC_KEY_SPECIAL_BRACES", type.isObject() ? " <"+type.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||||
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
addInjectMapper(" GENERIC_VALUE_SPECIAL_BRACES", valueType.isObject() ? " <"+valueType.getKeyType()+", %s>" : " <%s>").removeBraces().setBraceType("<>");
|
||||||
@@ -127,8 +128,8 @@ public class GlobalVariables
|
|||||||
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
|
addInjectMapper("OBJ_TO_"+fix, type.isObject() ? "%s" : "%s."+type.getKeyType(value)+"Value()").removeBraces();
|
||||||
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
|
addInjectMapper("CLASS_TO_"+fix, type.isObject() ? "("+type.getKeyType(value)+")%s" : "(("+type.getClassType(value)+")%s)."+type.getKeyType(value)+"Value()").removeBraces();
|
||||||
|
|
||||||
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "%s.hashCode()" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
addInjectMapper(fix+"_TO_HASH", type.isObject() ? "Objects.hashCode(%s)" : type.getClassType(value)+".hashCode(%s)").removeBraces();
|
||||||
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "%s.toString()" : type.getClassType(value)+".toString(%s)").removeBraces();
|
addInjectMapper(fix+"_TO_STRING", type.isObject() ? "Objects.toString(%s)" : type.getClassType(value)+".toString(%s)").removeBraces();
|
||||||
|
|
||||||
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
addSimpleMapper("CAST_"+fix+"_ARRAY ", type.isObject() ? "("+fix+"_TYPE[])" : "");
|
||||||
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");
|
||||||
@@ -157,6 +158,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");
|
||||||
@@ -171,6 +174,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");
|
||||||
@@ -190,6 +194,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");
|
||||||
@@ -217,7 +222,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", "");
|
||||||
@@ -225,10 +232,13 @@ 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");
|
||||||
|
addClassMapper("TASK", "Task");
|
||||||
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
addBiClassMapper("UNARY_OPERATOR", "UnaryOperator", "");
|
||||||
if(type.isObject())
|
if(type.isObject())
|
||||||
{
|
{
|
||||||
@@ -254,6 +264,7 @@ public class GlobalVariables
|
|||||||
|
|
||||||
public GlobalVariables createFunctions()
|
public GlobalVariables createFunctions()
|
||||||
{
|
{
|
||||||
|
addSimpleMapper("APPLY_KEY_VALUE", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
||||||
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
addSimpleMapper("APPLY_VALUE", valueType.isObject() ? "apply" : "applyAs"+valueType.getNonFileType());
|
||||||
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
|
addSimpleMapper("APPLY_CAST", "applyAs"+type.getCustomJDKType().getNonFileType());
|
||||||
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
addSimpleMapper("APPLY", type.isObject() ? "apply" : "applyAs"+type.getNonFileType());
|
||||||
@@ -284,6 +295,7 @@ public class GlobalVariables
|
|||||||
addFunctionValueMapper("MERGE", "merge");
|
addFunctionValueMapper("MERGE", "merge");
|
||||||
addFunctionMapper("NEXT", "next");
|
addFunctionMapper("NEXT", "next");
|
||||||
addFunctionMapper("PREVIOUS", "previous");
|
addFunctionMapper("PREVIOUS", "previous");
|
||||||
|
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
||||||
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
|
if(type.isObject()) addFunctionMapper("REMOVE_VALUE", "rem");
|
||||||
else addSimpleMapper("REMOVE_VALUE", "remove");
|
else addSimpleMapper("REMOVE_VALUE", "remove");
|
||||||
addFunctionMapper("REMOVE_KEY", "rem");
|
addFunctionMapper("REMOVE_KEY", "rem");
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
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;
|
||||||
@@ -10,7 +12,9 @@ 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.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;
|
||||||
@@ -29,12 +33,22 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,6 +69,23 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void afterFinish()
|
||||||
|
{
|
||||||
|
if(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 +104,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 +115,13 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void create(ClassType mainType, ClassType subType)
|
protected void create(ClassType mainType, ClassType subType)
|
||||||
@@ -151,6 +183,55 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
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
|
||||||
@@ -159,10 +240,14 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
|||||||
new PrimitiveCollectionsBuilder().process(false);
|
new PrimitiveCollectionsBuilder().process(false);
|
||||||
} else if(args.length == 1) {
|
} else if(args.length == 1) {
|
||||||
new PrimitiveCollectionsBuilder().process(Boolean.parseBoolean(args[0]));
|
new PrimitiveCollectionsBuilder().process(Boolean.parseBoolean(args[0]));
|
||||||
|
} else if(args.length == 2) {
|
||||||
|
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[1])).process(Boolean.parseBoolean(args[0]));
|
||||||
} else if(args.length == 3) {
|
} else if(args.length == 3) {
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
|
||||||
} else if(args.length == 4) {
|
} else if(args.length == 4) {
|
||||||
new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
new PrimitiveCollectionsBuilder(false, Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
||||||
|
} else if(args.length == 4) {
|
||||||
|
new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[4]), Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3]));
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Invalid argument count passed in");
|
System.out.println("Invalid argument count passed in");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|||||||
+54
-2
@@ -3,9 +3,12 @@ package speiger.src.collections.PACKAGE.collections;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.AbstractCollection;
|
import java.util.AbstractCollection;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
#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.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -79,23 +82,30 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
@Override
|
@Override
|
||||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
|
if(c.isEmpty()) return true;
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
if(!contains(iter.NEXT()))
|
if(!contains(iter.NEXT()))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(Collection<?> c) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
|
return c instanceof COLLECTION ? containsAll((COLLECTION KEY_GENERIC_TYPE)c) : super.containsAll(c);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean containsAny(Collection<?> c) {
|
public boolean containsAny(Collection<?> c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
for(Object e : c)
|
for(Object e : c)
|
||||||
if(contains(e))
|
if(contains(e))
|
||||||
return true;
|
return true;
|
||||||
@@ -111,6 +121,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
@Override
|
@Override
|
||||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
||||||
if(contains(iter.NEXT()))
|
if(contains(iter.NEXT()))
|
||||||
return true;
|
return true;
|
||||||
@@ -153,6 +164,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
Objects.requireNonNull(c);
|
Objects.requireNonNull(c);
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
if(c.contains(iter.NEXT())) {
|
if(c.contains(iter.NEXT())) {
|
||||||
@@ -163,6 +175,23 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
Objects.requireNonNull(r);
|
||||||
|
boolean modified = false;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
KEY_TYPE e = iter.NEXT();
|
||||||
|
if(c.contains(e)) {
|
||||||
|
r.accept(e);
|
||||||
|
iter.remove();
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
* A Type-Specific implementation of retainAll. This Implementation iterates over all elements and removes them as they were not found in the other collection.
|
||||||
* @param c the elements that should be kept
|
* @param c the elements that should be kept
|
||||||
@@ -187,6 +216,28 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
Objects.requireNonNull(c);
|
||||||
|
Objects.requireNonNull(r);
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
boolean modified = !isEmpty();
|
||||||
|
forEach(r);
|
||||||
|
clear();
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
boolean modified = false;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
KEY_TYPE e = iter.NEXT();
|
||||||
|
if(!c.contains(e)) {
|
||||||
|
r.accept(e);
|
||||||
|
iter.remove();
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
* A Type-Specific implementation of toArray that links to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
@@ -206,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+72
-1
@@ -8,7 +8,14 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.JAVA_STREAM;
|
import java.util.stream.JAVA_STREAM;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
#endif
|
#endif
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||||
|
#else
|
||||||
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,6 +122,16 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||||||
*/
|
*/
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type-Specific removeAll function that reduces (un)boxing.
|
||||||
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
|
* @param c the collection of elements that should be removed
|
||||||
|
* @param r elements that got removed
|
||||||
|
* @return true if any element was removed
|
||||||
|
* @see Collection#removeAll(Collection)
|
||||||
|
*/
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific retainAll function that reduces (un)boxing.
|
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||||
* @param c the collection of elements that should be kept
|
* @param c the collection of elements that should be kept
|
||||||
@@ -123,6 +140,27 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||||||
*/
|
*/
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type-Specific retainAll function that reduces (un)boxing.
|
||||||
|
* It also notifies the remover of which exact element is going to be removed.
|
||||||
|
* @param c the collection of elements that should be kept
|
||||||
|
* @param r elements that got removed
|
||||||
|
* @return true if any element was removed
|
||||||
|
* @see Collection#retainAll(Collection)
|
||||||
|
*/
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
|
* @param collection that the elements should be inserted to
|
||||||
|
* @param <E> the collection type
|
||||||
|
* @return the input with the desired elements
|
||||||
|
*/
|
||||||
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
|
collection.addAll(this);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Function that does a shallow clone of the Collection itself.
|
* A Function that does a shallow clone of the Collection itself.
|
||||||
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
* This function is more optimized then a copy constructor since the Collection does not have to be unsorted/resorted.
|
||||||
@@ -132,7 +170,18 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||||||
*/
|
*/
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy();
|
public COLLECTION KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Helper function that simplifies the process of creating a new Array.
|
||||||
|
* @param action the array creation function
|
||||||
|
* @return an array containing all of the elements in this collection
|
||||||
|
* @see Collection#toArray(Object[])
|
||||||
|
*/
|
||||||
|
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||||
|
return TO_ARRAY(action.get(size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
/**
|
/**
|
||||||
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
* A Type-Specific toArray function that delegates to {@link #TO_ARRAY(KEY_TYPE[])} with a newly created array.
|
||||||
* @return an array containing all of the elements in this collection
|
* @return an array containing all of the elements in this collection
|
||||||
@@ -219,6 +268,28 @@ public interface COLLECTION KEY_GENERIC_TYPE extends Collection<CLASS_TYPE>, ITE
|
|||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
|
* @return a new Collection that is synchronized
|
||||||
|
* @see COLLECTIONS#synchronize
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE synchronize() { return COLLECTIONS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new Collection Wrapper that is synchronized
|
||||||
|
* @see COLLECTIONS#synchronize
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE synchronize(Object mutex) { return COLLECTIONS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Collection that is unmodifiable
|
||||||
|
* @return a new Collection Wrapper that is unmodifiable
|
||||||
|
* @see COLLECTIONS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default COLLECTION KEY_GENERIC_TYPE unmodifiable() { return COLLECTIONS.unmodifiable(this); }
|
||||||
|
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
/**
|
/**
|
||||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||||
|
|||||||
+146
-2
@@ -1,18 +1,31 @@
|
|||||||
package speiger.src.collections.PACKAGE.collections;
|
package speiger.src.collections.PACKAGE.collections;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if !TYPE_OBJECT
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
#if !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
|
||||||
|
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.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||||
|
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
* A Type-Specific {@link Iterable} that reduces (un)boxing
|
||||||
@@ -78,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
|
||||||
@@ -118,6 +141,70 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
return ITERABLES.filter(this, filter);
|
return ITERABLES.filter(this, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to filter out duplicated elements
|
||||||
|
* @return a Iterable that filtered out all duplicated elements
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE distinct() {
|
||||||
|
return ITERABLES.distinct(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to limit the amount of elements
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @return a Iterable that is limited in length
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE limit(long limit) {
|
||||||
|
return ITERABLES.limit(this, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||||
|
* @param sorter that sorts the elements.
|
||||||
|
* @return a Iterable that is sorted
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||||
|
return ITERABLES.sorted(this, sorter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||||
|
* @param action the action that should be applied
|
||||||
|
* @return a Peeked Iterable
|
||||||
|
*/
|
||||||
|
default ITERABLE KEY_GENERIC_TYPE peek(CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return ITERABLES.peek(this, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function to reduce the usage of Streams and allows to collect all elements
|
||||||
|
* @param collection that the elements should be inserted to
|
||||||
|
* @param <E> the collection type
|
||||||
|
* @return the input with the desired elements
|
||||||
|
*/
|
||||||
|
default <E extends COLLECTION KEY_GENERIC_TYPE> E pour(E collection) {
|
||||||
|
ITERATORS.pour(iterator(), collection);
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
@@ -171,6 +258,63 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @param identity the start value
|
||||||
|
* @Type(E)
|
||||||
|
* @return the reduction result, returns identity if nothing was found
|
||||||
|
*/
|
||||||
|
default <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the
|
||||||
|
* elements of this Iterable
|
||||||
|
* @param operator the operation that should be applied
|
||||||
|
* @return the reduction result, returns null value if nothing was found
|
||||||
|
*/
|
||||||
|
default KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = iter.NEXT();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, iter.NEXT());
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to reduce stream usage that allows to count the valid elements.
|
* Helper function to reduce stream usage that allows to count the valid elements.
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ public interface SUPPLIER KEY_GENERIC_TYPE
|
|||||||
* @return the supplied value
|
* @return the supplied value
|
||||||
*/
|
*/
|
||||||
public KEY_TYPE GET_KEY();
|
public KEY_TYPE GET_KEY();
|
||||||
#if JDK_TYPE && PRIMITIVE
|
#if JDK_TYPE && PRIMITIVES
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default KEY_TYPE GET_JAVA() {
|
public default KEY_TYPE GET_JAVA() {
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
+207
-83
@@ -3,11 +3,15 @@ package speiger.src.collections.PACKAGE.lists;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of the {@link LIST} interface.
|
* Abstract implementation of the {@link LIST} interface.
|
||||||
@@ -15,9 +19,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
*/
|
*/
|
||||||
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
#if !TYPE_OBJECT
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific implementation of add function that delegates to {@link #add(int, KEY_TYPE)}
|
* A Type-Specific implementation of add function that delegates to {@link List#add(int, Object)}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean add(KEY_TYPE e) {
|
public boolean add(KEY_TYPE e) {
|
||||||
@@ -25,6 +28,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
/** {@inheritDoc}
|
/** {@inheritDoc}
|
||||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||||
* @deprecated Please use the corresponding type-specific function instead.
|
* @deprecated Please use the corresponding type-specific function instead.
|
||||||
@@ -71,7 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return index of the value that was searched for. -1 if not found
|
* @return index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -99,7 +103,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
||||||
* @param o the value that the index is searched for.
|
* @param o the value that the index is searched for.
|
||||||
* @return the last index of the value that was searched for. -1 if not found
|
* @return the last index of the value that was searched for. -1 if not found
|
||||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -155,6 +159,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) {
|
||||||
|
int index = indexOf(e);
|
||||||
|
if(index == -1) return false;
|
||||||
|
swapRemove(index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares if the list are the same.
|
* Compares if the list are the same.
|
||||||
*/
|
*/
|
||||||
@@ -205,7 +217,8 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
return new SUB_LIST(this, fromIndex, toIndex);
|
SanityChecks.checkArrayCapacity(size(), fromIndex, toIndex-fromIndex);
|
||||||
|
return new SubList(this, 0, fromIndex, toIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -220,6 +233,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
return new LIST_ITER(index);
|
return new LIST_ITER(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,124 +245,134 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public ABSTRACT_LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
private class SUB_LIST extends ABSTRACT_LIST KEY_GENERIC_TYPE {
|
private class SubList extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
ABSTRACT_LIST KEY_GENERIC_TYPE l;
|
{
|
||||||
int offset;
|
final ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
|
final int parentOffset;
|
||||||
|
final int offset;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
SUB_LIST(ABSTRACT_LIST KEY_GENERIC_TYPE l, int from, int to) {
|
public SubList(ABSTRACT_LIST KEY_GENERIC_TYPE list, int offset, int from, int to) {
|
||||||
if (from < 0) throw new IndexOutOfBoundsException("fromIndex = " + from);
|
this.list = list;
|
||||||
else if (to > l.size()) throw new IndexOutOfBoundsException("toIndex = " + to);
|
this.parentOffset = from;
|
||||||
else if (from > to) throw new IllegalArgumentException("fromIndex(" + from + ") > toIndex(" + to + ")");
|
this.offset = offset + from;
|
||||||
this.l = l;
|
this.size = to - from;
|
||||||
offset = from;
|
|
||||||
size = to - from;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(int index, KEY_TYPE e) {
|
public void add(int index, KEY_TYPE element) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
l.add(index+offset, e);
|
list.add(parentOffset+index, element);
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
public boolean addAll(int index, Collection<? extends CLASS_TYPE> c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||||
checkAddRange(index);
|
checkAddSubRange(index);
|
||||||
int size = c.size();
|
int add = c.size();
|
||||||
if(size == 0) return false;
|
if(add <= 0) return false;
|
||||||
l.addAll(index + offset, l);
|
list.addAll(parentOffset+index, c);
|
||||||
offset += size;
|
this.size += add;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAll(KEY_TYPE[] e, int offset, int length) {
|
|
||||||
if(length <= 0) return false;
|
|
||||||
l.addElements(this.offset, e, offset, length);
|
|
||||||
offset += length;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
checkRange(from);
|
checkAddSubRange(from);
|
||||||
l.addElements(from + this.offset, a, offset, length);
|
if(length <= 0) return;
|
||||||
size += length;
|
list.addElements(parentOffset+from, a, offset, length);
|
||||||
|
this.size += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
checkRange(from);
|
SanityChecks.checkArrayCapacity(size, from, length);
|
||||||
return l.getElements(from + this.offset, a, offset, length);
|
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||||
|
return list.getElements(from+parentOffset, a, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeElements(int from, int to) {
|
public void removeElements(int from, int to) {
|
||||||
checkRange(from);
|
if(to-from <= 0) return;
|
||||||
checkRange(to);
|
checkSubRange(from);
|
||||||
l.removeElements(from + offset, to + offset);
|
checkAddSubRange(to);
|
||||||
|
list.removeElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= to - from;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public <K> K[] extractElements(int from, int to, Class<K> clz) {
|
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||||
checkRange(from);
|
checkSubRange(from);
|
||||||
checkRange(to);
|
checkAddSubRange(to);
|
||||||
K[] a = l.extractElements(from + offset, to + offset, clz);
|
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return a;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] extractElements(int from, int to) {
|
public KEY_TYPE[] extractElements(int from, int to) {
|
||||||
checkRange(from);
|
checkSubRange(from);
|
||||||
checkRange(to);
|
checkAddSubRange(to);
|
||||||
KEY_TYPE[] a = l.extractElements(from + offset, to + offset);
|
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||||
size -= to - from;
|
size -= result.length;
|
||||||
return a;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
return l.GET_KEY(index + offset);
|
return list.GET_KEY(parentOffset+index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE e) {
|
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
return l.set(index + offset, e);
|
return list.set(parentOffset+index, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) {
|
||||||
|
checkSubRange(index);
|
||||||
|
if(index == size-1) {
|
||||||
|
KEY_TYPE result = list.REMOVE(parentOffset+size-1);
|
||||||
|
size--;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
KEY_TYPE result = list.set(index+parentOffset, list.GET_KEY(parentOffset+size-1));
|
||||||
|
list.REMOVE(parentOffset+size-1);
|
||||||
|
size--;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) {
|
public KEY_TYPE REMOVE(int index) {
|
||||||
checkRange(index);
|
checkSubRange(index);
|
||||||
|
KEY_TYPE result = list.REMOVE(index+parentOffset);
|
||||||
size--;
|
size--;
|
||||||
return l.REMOVE(index + offset);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -356,15 +380,115 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRange(int index) {
|
@Override
|
||||||
|
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
|
return new SubListIterator(this, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||||
|
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||||
|
return new SubList(this, offset, fromIndex, toIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkSubRange(int index) {
|
||||||
if (index < 0 || index >= size)
|
if (index < 0 || index >= size)
|
||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAddRange(int index) {
|
protected void checkAddSubRange(int index) {
|
||||||
if (index < 0 || index > size)
|
if (index < 0 || index > size)
|
||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SubListIterator implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ABSTRACT_LIST KEY_GENERIC_TYPE list;
|
||||||
|
int index;
|
||||||
|
int lastReturned = -1;
|
||||||
|
|
||||||
|
SubListIterator(ABSTRACT_LIST KEY_GENERIC_TYPE list, int index) {
|
||||||
|
this.list = list;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return index < list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
int i = index++;
|
||||||
|
return list.GET_KEY((lastReturned = i));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPrevious() {
|
||||||
|
return index > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
index--;
|
||||||
|
return list.GET_KEY((lastReturned = index));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int previousIndex() {
|
||||||
|
return index-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
|
list.REMOVE(lastReturned);
|
||||||
|
index = lastReturned;
|
||||||
|
lastReturned = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(KEY_TYPE e) {
|
||||||
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
|
list.set(lastReturned, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(KEY_TYPE e) {
|
||||||
|
list.add(index, e);
|
||||||
|
index++;
|
||||||
|
lastReturned = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, size() - index);
|
||||||
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, index);
|
||||||
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
@@ -382,8 +506,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
lastReturned = index;
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
return GET_KEY(index++);
|
int i = index++;
|
||||||
|
return GET_KEY((lastReturned = i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -393,8 +518,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
lastReturned = index;
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return GET_KEY(index--);
|
index--;
|
||||||
|
return GET_KEY((lastReturned = index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -409,34 +535,31 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
ABSTRACT_LIST.this.REMOVE(lastReturned);
|
||||||
if(lastReturned < index)
|
index = lastReturned;
|
||||||
index--;
|
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(KEY_TYPE e) {
|
public void set(KEY_TYPE e) {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
if(lastReturned == -1)
|
ABSTRACT_LIST.this.add(index, e);
|
||||||
throw new IllegalStateException();
|
index++;
|
||||||
ABSTRACT_LIST.this.add(index++, e);
|
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int skip(int amount) {
|
public int skip(int amount) {
|
||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, (size() - 1) - index);
|
int steps = Math.min(amount, size() - index);
|
||||||
index += steps;
|
index += steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,6 +568,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
int steps = Math.min(amount, index);
|
int steps = Math.min(amount, index);
|
||||||
index -= steps;
|
index -= steps;
|
||||||
|
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||||
return steps;
|
return steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+123
-8
@@ -9,6 +9,7 @@ import java.util.Iterator;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
@@ -29,6 +30,7 @@ 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;
|
||||||
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.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@@ -84,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,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) {
|
||||||
@@ -230,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
|
||||||
@@ -237,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;
|
||||||
@@ -305,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);
|
||||||
}
|
}
|
||||||
@@ -342,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
|
||||||
@@ -362,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,6 +671,45 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = data[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -733,6 +793,17 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KEY_TYPE swapRemove(int index) {
|
||||||
|
checkRange(index);
|
||||||
|
KEY_TYPE old = data[index];
|
||||||
|
size--;
|
||||||
|
data[index] = data[size];
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
data[size] = null;
|
||||||
|
#endif
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
* A Type-Specific implementation of remove. This implementation iterates over the elements until it finds the element that is searched for or it runs out of elements.
|
||||||
@@ -864,6 +935,22 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(!c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean modified = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function to retain all elements that were provided in the other collection
|
* A function to retain all elements that were provided in the other collection
|
||||||
* This function might delegate to a more appropriate function if necessary
|
* This function might delegate to a more appropriate function if necessary
|
||||||
@@ -891,6 +978,27 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
boolean modifed = size > 0;
|
||||||
|
forEach(r);
|
||||||
|
clear();
|
||||||
|
return modifed;
|
||||||
|
}
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean modified = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
/**
|
/**
|
||||||
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
|
* A optimized List#removeIf(Predicate) that more quickly removes elements from the list then the ArrayList implementation
|
||||||
@@ -934,8 +1042,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
public <E> E[] toArray(E[] a) {
|
public <E> E[] toArray(E[] a) {
|
||||||
if(a == null) a = (E[])new Object[size];
|
if(a == null) a = (E[])new Object[size];
|
||||||
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
|
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
System.arraycopy(data, 0, a, 0, size);
|
||||||
|
#else
|
||||||
for(int i = 0;i<size;i++)
|
for(int i = 0;i<size;i++)
|
||||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||||
|
#endif
|
||||||
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,6 +1057,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a.length < size) a = new KEY_TYPE[size];
|
if(a.length < size) a = new KEY_TYPE[size];
|
||||||
System.arraycopy(data, 0, a, 0, size);
|
System.arraycopy(data, 0, a, 0, size);
|
||||||
|
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1031,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,6 +1159,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
/**
|
/**
|
||||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||||
|
|||||||
+2176
File diff suppressed because it is too large
Load Diff
+121
-1
@@ -5,8 +5,10 @@ import java.util.Arrays;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
#endif
|
#endif
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -24,6 +26,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
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.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
@@ -330,6 +333,45 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0,m=data.length;i<m;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = data[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -340,6 +382,12 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
|
return new LIST_ITER(index);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE set(int index, KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
@@ -351,7 +399,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean REMOVE_KEY(KEY_TYPE type) { throw new UnsupportedOperationException(); }
|
public boolean REMOVE_KEY(KEY_TYPE type) { throw new UnsupportedOperationException(); }
|
||||||
@@ -370,6 +419,10 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
@@ -401,6 +454,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
|
else if(a.length < data.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), data.length);
|
||||||
for(int i = 0,m=data.length;i<m;i++)
|
for(int i = 0,m=data.length;i<m;i++)
|
||||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||||
|
if (a.length > data.length) a[data.length] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +463,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a.length < data.length) a = new KEY_TYPE[data.length];
|
if(a.length < data.length) a = new KEY_TYPE[data.length];
|
||||||
System.arraycopy(data, 0, a, 0, data.length);
|
System.arraycopy(data, 0, a, 0, data.length);
|
||||||
|
if (a.length > data.length) a[data.length] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,4 +504,69 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createArraySplititerator(data, data.length, 16464); }
|
||||||
|
|
||||||
|
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
|
int index;
|
||||||
|
|
||||||
|
LIST_ITER(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return index < size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
return GET_KEY(index++);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPrevious() {
|
||||||
|
return index > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE PREVIOUS() {
|
||||||
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
|
return GET_KEY(--index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int nextIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int previousIndex() {
|
||||||
|
return index-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int skip(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, size() - index);
|
||||||
|
index += steps;
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int back(int amount) {
|
||||||
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||||
|
int steps = Math.min(amount, index);
|
||||||
|
index -= steps;
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+259
-95
@@ -2,12 +2,14 @@ package speiger.src.collections.PACKAGE.lists;
|
|||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#else if PRIMITIVES
|
#else if PRIMITIVES
|
||||||
import java.nio.JAVA_BUFFER;
|
import java.nio.JAVA_BUFFER;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
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;
|
||||||
@@ -21,9 +23,12 @@ import java.util.function.JAVA_UNARY_OPERATOR;
|
|||||||
#endif
|
#endif
|
||||||
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.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.STACK;
|
import speiger.src.collections.PACKAGE.collections.STACK;
|
||||||
|
#else
|
||||||
|
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE;
|
||||||
@@ -147,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;
|
||||||
@@ -172,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
|
||||||
@@ -205,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;
|
||||||
@@ -253,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;
|
||||||
@@ -292,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,9 +323,8 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public int indexOf(Object o) {
|
public int indexOf(Object o) {
|
||||||
if(o == null) return -1;
|
|
||||||
Entry KEY_GENERIC_TYPE entry = first;
|
Entry KEY_GENERIC_TYPE entry = first;
|
||||||
for(int i = 0;entry != null;entry = entry.next) {
|
for(int i = 0;entry != null;entry = entry.next,i++) {
|
||||||
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -333,9 +333,8 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public int lastIndexOf(Object o) {
|
public int lastIndexOf(Object o) {
|
||||||
if(o == null) return -1;
|
|
||||||
Entry KEY_GENERIC_TYPE entry = last;
|
Entry KEY_GENERIC_TYPE entry = last;
|
||||||
for(int i = size-1;entry != null;entry = entry.prev) {
|
for(int i = size-1;entry != null;entry = entry.prev,i--) {
|
||||||
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
if(Objects.equals(KEY_TO_OBJ(entry.value), o)) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -350,7 +349,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public int indexOf(KEY_TYPE e) {
|
public int indexOf(KEY_TYPE e) {
|
||||||
Entry entry = first;
|
Entry entry = first;
|
||||||
for(int i = 0;entry != null;entry = entry.next) {
|
for(int i = 0;entry != null;entry = entry.next,i++) {
|
||||||
if(KEY_EQUALS(entry.value, e)) return i;
|
if(KEY_EQUALS(entry.value, e)) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -359,26 +358,17 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public int lastIndexOf(KEY_TYPE e) {
|
public int lastIndexOf(KEY_TYPE e) {
|
||||||
Entry entry = last;
|
Entry entry = last;
|
||||||
for(int i = size-1;entry != null;entry = entry.prev) {
|
for(int i = size-1;entry != null;entry = entry.prev,i--) {
|
||||||
if(KEY_EQUALS(entry.value, e)) return i;
|
if(KEY_EQUALS(entry.value, e)) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
return new ListIter(first, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator() {
|
|
||||||
return new ListIter(first, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||||
if(index == size-1) return new ListIter(last, index);
|
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
|
||||||
|
if(index == size) return new ListIter(null, index);
|
||||||
if(index == 0) return new ListIter(first, index);
|
if(index == 0) return new ListIter(first, index);
|
||||||
return new ListIter(getNode(index), index);
|
return new ListIter(getNode(index), index);
|
||||||
}
|
}
|
||||||
@@ -454,6 +444,45 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = entry.value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, entry.value);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -503,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,7 +550,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeFirst(KEY_TYPE e) {
|
public boolean removeFirst(KEY_TYPE e) {
|
||||||
if(size == 0) return false;
|
if(size == 0) return false;
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry.next != null;entry = entry.next) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
if(KEY_EQUALS(entry.value, e)) {
|
if(KEY_EQUALS(entry.value, e)) {
|
||||||
unlink(entry);
|
unlink(entry);
|
||||||
return true;
|
return true;
|
||||||
@@ -533,7 +562,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeLast(KEY_TYPE e) {
|
public boolean removeLast(KEY_TYPE e) {
|
||||||
if(size == 0) return false;
|
if(size == 0) return false;
|
||||||
for(Entry KEY_GENERIC_TYPE entry = last;entry.prev != null;entry = entry.prev) {
|
for(Entry KEY_GENERIC_TYPE entry = last;entry != null;entry = entry.prev) {
|
||||||
if(KEY_EQUALS(entry.value, e)) {
|
if(KEY_EQUALS(entry.value, e)) {
|
||||||
unlink(entry);
|
unlink(entry);
|
||||||
return true;
|
return true;
|
||||||
@@ -542,11 +571,77 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) {
|
||||||
|
checkRange(index);
|
||||||
|
Entry KEY_GENERIC_TYPE entry = getNode(index);
|
||||||
|
if(entry == null) return EMPTY_KEY_VALUE;
|
||||||
|
if(entry.next == null) return unlinkLast(entry);
|
||||||
|
Entry KEY_GENERIC_TYPE before = entry.prev;
|
||||||
|
KEY_TYPE result = unlink(entry);
|
||||||
|
if(before == null) {
|
||||||
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
|
last = temp.prev;
|
||||||
|
last.next = null;
|
||||||
|
temp.next = first;
|
||||||
|
temp.prev = null;
|
||||||
|
first.prev = temp;
|
||||||
|
first = temp;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if(before.next != last) {
|
||||||
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
|
last = temp.prev;
|
||||||
|
last.next = null;
|
||||||
|
temp.next = before.next;
|
||||||
|
temp.prev = before;
|
||||||
|
before.next = temp;
|
||||||
|
temp.next.prev = temp;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) {
|
||||||
|
if(size == 0) return false;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = last;entry != null;entry = entry.prev) {
|
||||||
|
if(KEY_EQUALS(entry.value, e)) {
|
||||||
|
if(entry.next == null) {
|
||||||
|
unlinkLast(entry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Entry KEY_GENERIC_TYPE before = entry.prev;
|
||||||
|
unlink(entry);
|
||||||
|
if(before == null) {
|
||||||
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
|
last = temp.prev;
|
||||||
|
last.next = null;
|
||||||
|
temp.next = first;
|
||||||
|
temp.prev = null;
|
||||||
|
first.prev = temp;
|
||||||
|
first = temp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(before.next != last) {
|
||||||
|
Entry KEY_GENERIC_TYPE temp = last;
|
||||||
|
last = temp.prev;
|
||||||
|
last.next = null;
|
||||||
|
temp.next = before.next;
|
||||||
|
temp.prev = before;
|
||||||
|
before.next = temp;
|
||||||
|
temp.next.prev = temp;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(Object e) {
|
public boolean remove(Object e) {
|
||||||
if(size <= 0) return false;
|
if(size <= 0) return false;
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry.next != null;entry = entry.next) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
if(KEY_EQUALS(entry.value, e)) {
|
if(KEY_EQUALS(entry.value, e)) {
|
||||||
unlink(entry);
|
unlink(entry);
|
||||||
return true;
|
return true;
|
||||||
@@ -565,7 +660,8 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) {
|
public KEY_TYPE REMOVE(int index) {
|
||||||
checkRange(index);
|
checkRange(index);
|
||||||
return unlink(getNode(index));
|
Entry KEY_GENERIC_TYPE entry = getNode(index);
|
||||||
|
return entry == null ? EMPTY_KEY_VALUE : unlink(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -577,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--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,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;
|
||||||
}
|
}
|
||||||
@@ -626,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;
|
||||||
}
|
}
|
||||||
@@ -714,6 +816,27 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
if(c.isEmpty()) return false;
|
||||||
|
boolean modified = false;
|
||||||
|
int j = 0;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;) {
|
||||||
|
if(c.contains(entry.value)) {
|
||||||
|
r.accept(entry.value);
|
||||||
|
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||||
|
unlink(entry);
|
||||||
|
entry = next;
|
||||||
|
modified = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else j++;
|
||||||
|
entry = entry.next;
|
||||||
|
}
|
||||||
|
size = j;
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
if(c.isEmpty()) {
|
if(c.isEmpty()) {
|
||||||
@@ -738,6 +861,32 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
if(c.isEmpty()) {
|
||||||
|
boolean changed = size > 0;
|
||||||
|
forEach(r);
|
||||||
|
clear();
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
boolean modified = false;
|
||||||
|
int j = 0;
|
||||||
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;) {
|
||||||
|
if(!c.contains(entry.value)) {
|
||||||
|
r.accept(entry.value);
|
||||||
|
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||||
|
unlink(entry);
|
||||||
|
entry = next;
|
||||||
|
modified = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else j++;
|
||||||
|
entry = entry.next;
|
||||||
|
}
|
||||||
|
size = j;
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
public boolean removeIf(Predicate<? super CLASS_TYPE> filter) {
|
||||||
@@ -798,6 +947,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
a[i++] = (E)KEY_TO_OBJ(entry.value);
|
a[i++] = (E)KEY_TO_OBJ(entry.value);
|
||||||
}
|
}
|
||||||
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,11 +957,18 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
if(a.length < size) a = new KEY_TYPE[size];
|
if(a.length < size) a = new KEY_TYPE[size];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
for(Entry KEY_GENERIC_TYPE entry = first;entry != null;entry = entry.next) {
|
||||||
a[i++] = KEY_TO_OBJ(entry.value);
|
a[i++] = entry.value;
|
||||||
}
|
}
|
||||||
|
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public T[] toArray(Int2ObjectFunction<T[]> action) {
|
||||||
|
return super.toArray(action);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
@@ -957,27 +1114,32 @@ 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
|
||||||
{
|
{
|
||||||
Entry KEY_GENERIC_TYPE node;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
Entry KEY_GENERIC_TYPE lastReturned;
|
Entry KEY_GENERIC_TYPE lastReturned;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
ListIter(Entry KEY_GENERIC_TYPE node, int index) {
|
ListIter(Entry KEY_GENERIC_TYPE next, int index) {
|
||||||
this.node = node;
|
this.next = next;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return node != null;
|
return index < size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPrevious() {
|
public boolean hasPrevious() {
|
||||||
return node != null;
|
return index > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -993,23 +1155,26 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
if(lastReturned == null) throw new IllegalStateException();
|
||||||
if(lastReturned.next == node) index--;
|
Entry KEY_GENERIC_TYPE lastNext = lastReturned.next;
|
||||||
unlink(lastReturned);
|
unlink(lastReturned);
|
||||||
|
if (next == lastReturned) next = lastNext;
|
||||||
|
else index--;
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
lastReturned = node;
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
node = node.prev;
|
lastReturned = next = (next == null) ? last : next.prev;
|
||||||
index--;
|
index--;
|
||||||
return lastReturned.value;
|
return lastReturned.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
lastReturned = node;
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
node = node.next;
|
lastReturned = next;
|
||||||
|
next = next.next;
|
||||||
index++;
|
index++;
|
||||||
return lastReturned.value;
|
return lastReturned.value;
|
||||||
}
|
}
|
||||||
@@ -1022,10 +1187,9 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(KEY_TYPE e) {
|
public void add(KEY_TYPE e) {
|
||||||
if(lastReturned == null) throw new IllegalStateException();
|
|
||||||
if(node.next == null) linkLast(e);
|
|
||||||
else linkBefore(e, node);
|
|
||||||
lastReturned = null;
|
lastReturned = null;
|
||||||
|
if (next == null) linkLast(e);
|
||||||
|
else linkBefore(e, next);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1088,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
|
||||||
@@ -1154,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
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
|||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
@@ -50,6 +51,26 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||||||
public void add(int index, KEY_TYPE e);
|
public void add(int index, KEY_TYPE e);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* A Helper function that will only add elements if it is not present.
|
||||||
|
* @param e the element to add
|
||||||
|
* @return true if the list was modified
|
||||||
|
*/
|
||||||
|
public default boolean addIfAbsent(KEY_TYPE e) {
|
||||||
|
if(indexOf(e) == -1) return add(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that will only add elements if it is present.
|
||||||
|
* @param e the element to add
|
||||||
|
* @return true if the list was modified
|
||||||
|
*/
|
||||||
|
public default boolean addIfPresent(KEY_TYPE e) {
|
||||||
|
if(indexOf(e) != -1) return add(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type-Specific addAll Function to reduce (un)boxing
|
* A Type-Specific addAll Function to reduce (un)boxing
|
||||||
* @param c the elements that need to be added
|
* @param c the elements that need to be added
|
||||||
@@ -206,6 +227,22 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||||||
*/
|
*/
|
||||||
public void removeElements(int from, int to);
|
public void removeElements(int from, int to);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Highly Optimized remove function that removes the desired element.
|
||||||
|
* But instead of shifting the elements to the left it moves the last element to the removed space.
|
||||||
|
* @param index the index of the element to be removed
|
||||||
|
* @return the element previously at the specified position
|
||||||
|
*/
|
||||||
|
public KEY_TYPE swapRemove(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Highly Optimized remove function that removes the desired element.
|
||||||
|
* But instead of shifting the elements to the left it moves the last element to the removed space.
|
||||||
|
* @param e the element that should be removed
|
||||||
|
* @return true if the element was removed
|
||||||
|
*/
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e);
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A function to fast extract elements out of the list, this removes the elements that were fetched.
|
* A function to fast extract elements out of the list, this removes the elements that were fetched.
|
||||||
@@ -342,6 +379,28 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
|||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int from, int to);
|
public LIST KEY_GENERIC_TYPE subList(int from, int to);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped List that is Synchronized
|
||||||
|
* @return a new List that is synchronized
|
||||||
|
* @see LISTS#synchronize
|
||||||
|
*/
|
||||||
|
public default LIST KEY_GENERIC_TYPE synchronize() { return LISTS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped List that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new List Wrapper that is synchronized
|
||||||
|
* @see LISTS#synchronize
|
||||||
|
*/
|
||||||
|
public default LIST KEY_GENERIC_TYPE synchronize(Object mutex) { return LISTS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped List that is unmodifiable
|
||||||
|
* @return a new List Wrapper that is unmodifiable
|
||||||
|
* @see LISTS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default LIST KEY_GENERIC_TYPE unmodifiable() { return LISTS.unmodifiable(this); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function to ensure the elements are within the requested size.
|
* A function to ensure the elements are within the requested size.
|
||||||
* If smaller then the stored elements they get removed as needed.
|
* If smaller then the stored elements they get removed as needed.
|
||||||
|
|||||||
+25
-2
@@ -90,6 +90,15 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||||
|
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||||
|
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||||
|
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m) {
|
public void putAllIfAbsent(MAP KEY_VALUE_GENERIC_TYPE m) {
|
||||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m))
|
||||||
@@ -276,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);
|
||||||
@@ -297,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
|
||||||
@@ -495,7 +518,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(key) + "->" + VALUE_TO_STRING(value);
|
return KEY_TO_STRING(key) + "=" + VALUE_TO_STRING(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2447
File diff suppressed because it is too large
Load Diff
+162
-62
@@ -1,15 +1,14 @@
|
|||||||
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;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.Objects;
|
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
|
||||||
@@ -17,16 +16,19 @@ 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;
|
||||||
#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.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;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||||
|
#if !SAME_TYPE
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
|
#endif
|
||||||
#if !VALUE_OBJECT && !SAME_TYPE
|
#if !VALUE_OBJECT && !SAME_TYPE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||||
@@ -47,11 +49,14 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
|
||||||
|
#endif
|
||||||
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;
|
||||||
|
|
||||||
@@ -62,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;
|
||||||
@@ -279,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);
|
||||||
@@ -301,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);
|
||||||
@@ -354,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();
|
||||||
@@ -378,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)) {
|
||||||
@@ -402,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)) {
|
||||||
@@ -429,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
|
||||||
@@ -464,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;
|
||||||
}
|
}
|
||||||
@@ -611,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
|
||||||
@@ -747,6 +736,37 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
E state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -780,8 +800,19 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return LINKED_CUSTOM_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return LINKED_CUSTOM_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
int index = LINKED_CUSTOM_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||||
|
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_CUSTOM_HASH_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||||
|
#endif
|
||||||
|
int index = LINKED_CUSTOM_HASH_MAP.this.findIndex((CLASS_TYPE)entry.getKey());
|
||||||
|
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_CUSTOM_HASH_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -809,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
|
||||||
@@ -833,7 +853,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_CUSTOM_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -846,7 +866,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) {
|
public boolean remove(KEY_TYPE o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_CUSTOM_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,6 +991,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -995,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 {
|
||||||
@@ -1100,6 +1154,52 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = values[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
|
|||||||
+217
-19
@@ -6,6 +6,7 @@ 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 java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
@@ -15,6 +16,9 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
|||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
#if !SAME_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
@@ -33,10 +37,17 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
|||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||||
#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;
|
||||||
|
|
||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
#else if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||||
@@ -275,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
|
||||||
@@ -296,8 +316,8 @@ 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(VALUE_EQUALS(value, values[nullIndex])) return true;
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
for(int i = nullIndex-1;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;
|
||||||
}
|
}
|
||||||
@@ -306,9 +326,17 @@ 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) {
|
||||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
#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--)
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||||
|
#else
|
||||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +355,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public CLASS_VALUE_TYPE remove(Object key) {
|
public CLASS_VALUE_TYPE remove(Object key) {
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
if(!(key instanceof CLASS_TYPE)) return getDefaultReturnValue();
|
if(!(key instanceof CLASS_TYPE)) return getDefaultReturnValue();
|
||||||
@@ -367,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;
|
||||||
@@ -484,6 +515,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||||
@@ -502,6 +534,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||||
@@ -509,11 +542,18 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
insert(-index-1, key, newValue);
|
insert(-index-1, key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
return values[index];
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = mappingFunction.GET_VALUE(key);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||||
|
Objects.requireNonNull(valueProvider);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||||
@@ -521,13 +561,20 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
insert(-index-1, key, newValue);
|
insert(-index-1, key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
return values[index];
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = valueProvider.VALUE_GET_KEY();
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) return getDefaultReturnValue();
|
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -539,8 +586,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
Objects.requireNonNull(value);
|
||||||
|
#endif
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
if(index >= 0)
|
if(index >= 0)
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -556,7 +607,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||||
KEY_TYPE key = entry.ENTRY_KEY();
|
KEY_TYPE key = entry.ENTRY_KEY();
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
if(index >= 0)
|
if(index >= 0)
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -581,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);
|
||||||
}
|
}
|
||||||
@@ -592,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;
|
||||||
}
|
}
|
||||||
@@ -622,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)) {
|
||||||
@@ -773,7 +827,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,6 +928,39 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
E state = identity;
|
||||||
|
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -924,8 +1011,19 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return CUSTOM_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return CUSTOM_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
int index = CUSTOM_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||||
|
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), CUSTOM_HASH_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(!(entry.getKey() instanceof CLASS_TYPE)) return false;
|
||||||
|
#endif
|
||||||
|
int index = CUSTOM_HASH_MAP.this.findIndex((CLASS_TYPE)entry.getKey());
|
||||||
|
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(CUSTOM_HASH_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -954,7 +1052,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
CUSTOM_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -967,7 +1065,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) {
|
public boolean remove(KEY_TYPE o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
CUSTOM_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -997,9 +1095,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
if(containsNull) action.accept(keys[nullIndex]);
|
if(containsNull) action.accept(keys[nullIndex]);
|
||||||
for(int i = nullIndex-1;i>=0;i--)
|
for(int i = nullIndex-1;i>=0;i--)
|
||||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]);
|
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(keys[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1045,6 +1144,54 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.apply(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.apply(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -1153,6 +1300,54 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = values[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = values[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -1216,6 +1411,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
private class MapIterator {
|
private class MapIterator {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
@@ -1247,6 +1443,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
|
|
||||||
public int nextEntry() {
|
public int nextEntry() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||||
@@ -1266,9 +1463,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
|||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
values[nullIndex] = EMPTY_VALUE;
|
values[nullIndex] = EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
CUSTOM_HASH_MAP.this.remove(wrapped.GET_KEY(-pos - 1));
|
CUSTOM_HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
|
|||||||
+192
-71
@@ -1,15 +1,14 @@
|
|||||||
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;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.Objects;
|
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
|
||||||
@@ -17,15 +16,18 @@ 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;
|
||||||
#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.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;
|
||||||
|
#if !SAME_TYPE
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
|
#endif
|
||||||
#if !VALUE_OBJECT && !SAME_TYPE
|
#if !VALUE_OBJECT && !SAME_TYPE
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||||
@@ -46,11 +48,14 @@ import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_C
|
|||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
|
||||||
|
#endif
|
||||||
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;
|
||||||
|
|
||||||
@@ -61,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;
|
||||||
@@ -256,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);
|
||||||
@@ -278,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);
|
||||||
@@ -314,6 +319,33 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
return values[index];
|
return values[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(VALUE_TYPE value) {
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(VALUE_EQUALS(values[index], value)) return true;
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
@ValuePrimitive
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
if(VALUE_EQUALS(values[index], value)) return true;
|
||||||
|
#else
|
||||||
|
if((value == null && values[index] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[index], value)) return true;
|
||||||
|
#endif
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
public LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE copy() {
|
||||||
LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(0, loadFactor);
|
LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(0, loadFactor);
|
||||||
@@ -331,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();
|
||||||
@@ -355,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)) {
|
||||||
@@ -379,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)) {
|
||||||
@@ -406,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
|
||||||
@@ -441,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;
|
||||||
}
|
}
|
||||||
@@ -588,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
|
||||||
@@ -724,6 +740,37 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
E state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -757,8 +804,16 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return LINKED_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return LINKED_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
int index = LINKED_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||||
|
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_HASH_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
int index = LINKED_HASH_MAP.this.findIndex(entry.getKey());
|
||||||
|
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_HASH_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -786,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
|
||||||
@@ -810,7 +854,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,15 +867,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) {
|
public boolean remove(KEY_TYPE o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#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(); }
|
||||||
@@ -941,13 +983,59 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1) {
|
||||||
if(!filter.TEST_VALUE(keys[index])) return false;
|
if(!filter.TEST_VALUE(keys[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -967,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 {
|
||||||
@@ -1059,7 +1135,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1) {
|
||||||
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
if(filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
@@ -1071,13 +1147,59 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
|||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
if(size() <= 0) return true;
|
if(size() <= 0) return true;
|
||||||
int index = firstIndex;
|
int index = firstIndex;
|
||||||
while(index != -1){
|
while(index != -1) {
|
||||||
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
if(!filter.VALUE_TEST_VALUE(values[index])) return false;
|
||||||
index = (int)links[index];
|
index = (int)links[index];
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = values[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -1203,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 {
|
||||||
@@ -1273,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;
|
||||||
|
|||||||
+211
-17
@@ -6,6 +6,7 @@ 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 java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
@@ -15,6 +16,9 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
|||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
#if !SAME_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
@@ -34,9 +38,15 @@ import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
|||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
|
|
||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
#else if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
#if !TYPE_OBJECT && !VALUE_OBJECT || !VALUE_OBJECT
|
||||||
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
|
||||||
@@ -50,6 +60,7 @@ import speiger.src.collections.objects.functions.function.Object2BooleanFunction
|
|||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.VALUE_BI_FROM_OBJECT_CONSUMER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
@@ -250,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
|
||||||
@@ -267,7 +287,7 @@ 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) {
|
||||||
if(VALUE_EQUALS(value, values[nullIndex])) return true;
|
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||||
for(int i = nullIndex-1;i >= 0;i--)
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && 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;
|
||||||
@@ -277,9 +297,17 @@ 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) {
|
||||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
#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--)
|
for(int i = nullIndex-1;i >= 0;i--)
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||||
|
#else
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
if(KEY_EQUALS_NOT_NULL(keys[i]) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +326,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public CLASS_VALUE_TYPE remove(Object key) {
|
public CLASS_VALUE_TYPE remove(Object key) {
|
||||||
int slot = findIndex(key);
|
int slot = findIndex(key);
|
||||||
if(slot < 0) return VALUE_TO_OBJ(getDefaultReturnValue());
|
if(slot < 0) return VALUE_TO_OBJ(getDefaultReturnValue());
|
||||||
@@ -335,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;
|
||||||
@@ -445,6 +476,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||||
@@ -463,6 +495,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||||
@@ -470,11 +503,18 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
insert(-index-1, key, newValue);
|
insert(-index-1, key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
return values[index];
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = mappingFunction.GET_VALUE(key);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||||
|
Objects.requireNonNull(valueProvider);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) {
|
if(index < 0) {
|
||||||
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||||
@@ -482,13 +522,20 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
insert(-index-1, key, newValue);
|
insert(-index-1, key, newValue);
|
||||||
return newValue;
|
return newValue;
|
||||||
}
|
}
|
||||||
return values[index];
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = valueProvider.VALUE_GET_KEY();
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
if(index < 0) return getDefaultReturnValue();
|
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -500,8 +547,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
Objects.requireNonNull(value);
|
||||||
|
#endif
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
VALUE_TYPE newValue = index < 0 ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
if(index >= 0)
|
if(index >= 0)
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -517,7 +568,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||||
KEY_TYPE key = entry.ENTRY_KEY();
|
KEY_TYPE key = entry.ENTRY_KEY();
|
||||||
int index = findIndex(key);
|
int index = findIndex(key);
|
||||||
VALUE_TYPE newValue = index < 0 ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
VALUE_TYPE newValue = index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
if(index >= 0)
|
if(index >= 0)
|
||||||
removeIndex(index);
|
removeIndex(index);
|
||||||
@@ -542,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);
|
||||||
}
|
}
|
||||||
@@ -553,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;
|
||||||
}
|
}
|
||||||
@@ -582,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)) {
|
||||||
@@ -733,7 +787,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,6 +888,39 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
E state = identity;
|
||||||
|
if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]));
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = new BasicEntryKV_BRACES(keys[i], values[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -884,8 +971,16 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
int index = HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||||
|
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), HASH_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
int index = HASH_MAP.this.findIndex(entry.getKey());
|
||||||
|
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(HASH_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -914,7 +1009,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -927,7 +1022,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(KEY_TYPE o) {
|
public boolean remove(KEY_TYPE o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
HASH_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,6 +1100,54 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_KEY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.apply(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.apply(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -1113,6 +1256,54 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, values[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = values[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = values[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, values[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -1176,6 +1367,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
private class MapIterator {
|
private class MapIterator {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
@@ -1207,6 +1399,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
|
|
||||||
public int nextEntry() {
|
public int nextEntry() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
int value = findIndex(wrapped.GET_KEY(nextIndex));
|
||||||
@@ -1226,9 +1419,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
|||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
values[nullIndex] = EMPTY_VALUE;
|
values[nullIndex] = EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
HASH_MAP.this.remove(wrapped.GET_KEY(-pos - 1));
|
HASH_MAP.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
|
|||||||
+197
-62
@@ -1,16 +1,15 @@
|
|||||||
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;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
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
|
||||||
@@ -19,11 +18,16 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
|||||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
#if !SAME_TYPE
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||||
|
#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;
|
||||||
@@ -45,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;
|
||||||
@@ -61,11 +64,14 @@ import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_ARRAYS;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
@@ -76,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;
|
||||||
@@ -95,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;
|
||||||
|
|
||||||
@@ -229,18 +235,34 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
{
|
{
|
||||||
KEY_TYPE o = a[i];
|
KEY_TYPE o = a[i];
|
||||||
if(KEY_EQUALS_NULL(o)) {
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
if(!containsNull) size++;
|
if(!containsNull) {
|
||||||
|
size++;
|
||||||
|
if(prev != -1) {
|
||||||
|
newLinks[prev] ^= ((newLinks[prev] ^ (newSize & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
newLinks[newSize] ^= ((newLinks[newSize] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||||
|
prev = newSize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev = firstIndex = newSize;
|
||||||
|
newLinks[newSize] = -1L;
|
||||||
|
}
|
||||||
|
}
|
||||||
containsNull = true;
|
containsNull = true;
|
||||||
|
newValues[newSize] = b[i];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean found = true;
|
boolean found = true;
|
||||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & newMask;
|
int pos = HashUtil.mix(KEY_TO_HASH(o)) & newMask;
|
||||||
KEY_TYPE current = newKeys[pos];
|
KEY_TYPE current = newKeys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
if(KEY_EQUALS(current, o)) continue;
|
if(KEY_EQUALS(current, o)) {
|
||||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & mask)]))) {
|
newValues[pos] = b[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & newMask)]))) {
|
||||||
if(KEY_EQUALS(current, o)) {
|
if(KEY_EQUALS(current, o)) {
|
||||||
found = false;
|
found = false;
|
||||||
|
newValues[pos] = b[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +270,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
if(found) {
|
if(found) {
|
||||||
size++;
|
size++;
|
||||||
newKeys[pos] = o;
|
newKeys[pos] = o;
|
||||||
values[pos] = b[i];
|
newValues[pos] = b[i];
|
||||||
if(prev != -1) {
|
if(prev != -1) {
|
||||||
newLinks[prev] ^= ((newLinks[prev] ^ (pos & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
newLinks[prev] ^= ((newLinks[prev] ^ (pos & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
newLinks[pos] ^= ((newLinks[pos] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
newLinks[pos] ^= ((newLinks[pos] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||||
@@ -260,7 +282,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nullIndex = size;
|
nullIndex = newSize;
|
||||||
mask = newMask;
|
mask = newMask;
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
values = newValues;
|
values = newValues;
|
||||||
@@ -273,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(); }
|
||||||
@@ -308,9 +330,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(VALUE_TYPE value) {
|
public boolean containsValue(VALUE_TYPE value) {
|
||||||
if(VALUE_EQUALS(value, values[nullIndex])) return true;
|
int index = firstIndex;
|
||||||
for(int i = nullIndex-1;i >= 0;i--)
|
while(index != -1) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
if(VALUE_EQUALS(values[index], value)) return true;
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,9 +342,15 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
@Override
|
@Override
|
||||||
@ValuePrimitive
|
@ValuePrimitive
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
if((value == null && VALUE_EQUALS(values[nullIndex], getDefaultReturnValue())) || EQUALS_VALUE_TYPE(values[nullIndex], value)) return true;
|
int index = firstIndex;
|
||||||
for(int i = nullIndex-1;i >= 0;i--)
|
while(index != -1) {
|
||||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && ((value == null && values[i] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[i], value))) return true;
|
#if VALUE_OBJECT
|
||||||
|
if(VALUE_EQUALS(values[index], value)) return true;
|
||||||
|
#else
|
||||||
|
if((value == null && values[index] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[index], value)) return true;
|
||||||
|
#endif
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,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;
|
||||||
}
|
}
|
||||||
@@ -432,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;
|
||||||
@@ -496,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)) {
|
||||||
@@ -536,6 +560,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
}
|
}
|
||||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
if(!(key instanceof CLASS_TYPE)) return false;
|
||||||
|
#endif
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
#if TYPE_OBJECT && VALUE_OBJECT
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
return KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], value);
|
return KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], value);
|
||||||
@@ -557,11 +584,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -685,6 +712,37 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E reduce(E identity, BiFunction<E, MAP.Entry KEY_VALUE_GENERIC_TYPE, E> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
E state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE reduce(ObjectObjectUnaryOperator<MAP.Entry KEY_VALUE_GENERIC_TYPE, MAP.Entry KEY_VALUE_GENERIC_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE state = null;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = new BasicEntryKV_BRACES(keys[index], values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index]));
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Object2BooleanFunction<MAP.Entry KEY_VALUE_GENERIC_TYPE> filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -718,8 +776,16 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return IMMUTABLE_HASH_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return IMMUTABLE_HASH_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
int index = IMMUTABLE_HASH_MAP.this.findIndex(entry.ENTRY_KEY());
|
||||||
|
if(index >= 0) return VALUE_EQUALS(entry.ENTRY_VALUE(), IMMUTABLE_HASH_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
int index = IMMUTABLE_HASH_MAP.this.findIndex(entry.getKey());
|
||||||
|
if(index >= 0) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(IMMUTABLE_HASH_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -735,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
|
||||||
@@ -879,6 +934,52 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(SINGLE_UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_KEY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_KEY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -903,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 {
|
||||||
@@ -1006,6 +1095,52 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_TYPE identity, VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <VALUE_SPECIAL_TYPE> VALUE_SPECIAL_TYPE reduce(VALUE_SPECIAL_TYPE identity, BiFunction<VALUE_SPECIAL_TYPE, VALUE_TYPE, VALUE_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.apply(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE reduce(VALUE_SINGLE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
VALUE_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = values[index];
|
||||||
|
index = (int)links[index];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, values[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
public VALUE_TYPE findFirst(VALUE_PREDICATE VALUE_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
|
|||||||
+193
-1048
File diff suppressed because it is too large
Load Diff
+359
-14
@@ -3,9 +3,8 @@ package speiger.src.collections.PACKAGE.maps.impl.misc;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
#if VALUE_OBJECT
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#endif
|
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;
|
||||||
@@ -13,6 +12,14 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
|||||||
#if !VALUE_OBJECT
|
#if !VALUE_OBJECT
|
||||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||||
|
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||||
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
|
import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
|
||||||
import speiger.src.collections.objects.maps.interfaces.MAP;
|
import speiger.src.collections.objects.maps.interfaces.MAP;
|
||||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||||
@@ -28,13 +35,13 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
|||||||
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
/** Enum Type that is being used */
|
/** Enum Type that is being used */
|
||||||
protected final Class<T> keyType;
|
protected Class<T> keyType;
|
||||||
/** The Backing keys array. */
|
/** The Backing keys array. */
|
||||||
protected transient final T[] keys;
|
protected transient T[] keys;
|
||||||
/** The Backing values array */
|
/** The Backing values array */
|
||||||
protected transient final VALUE_TYPE[] values;
|
protected transient VALUE_TYPE[] values;
|
||||||
/** The Backing array that indicates which index is present or not */
|
/** The Backing array that indicates which index is present or not */
|
||||||
protected transient final long[] present;
|
protected transient long[] present;
|
||||||
/** Amount of Elements stored in the ArrayMap */
|
/** Amount of Elements stored in the ArrayMap */
|
||||||
protected int size = 0;
|
protected int size = 0;
|
||||||
/** EntrySet cache */
|
/** EntrySet cache */
|
||||||
@@ -44,6 +51,9 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
/** Values cache */
|
/** Values cache */
|
||||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||||
|
|
||||||
|
protected ENUM_MAP() {
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param keyType the type of Enum that should be used
|
* @param keyType the type of Enum that should be used
|
||||||
@@ -55,6 +65,86 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
present = new long[((keys.length - 1) >> 6) + 1];
|
present = new long[((keys.length - 1) >> 6) + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
/**
|
||||||
|
* Helper constructor that allow to create a EnumMap from boxed values (it will unbox them)
|
||||||
|
* @param keys the keys that should be put into the EnumMap
|
||||||
|
* @param values the values that should be put into the EnumMap.
|
||||||
|
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||||
|
*/
|
||||||
|
public ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) {
|
||||||
|
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||||
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
|
keyType = keys[0].getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
|
putAll(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Helper constructor that allow to create a EnumMap from unboxed values
|
||||||
|
* @param keys the keys that should be put into the map
|
||||||
|
* @param values the values that should be put into the map.
|
||||||
|
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||||
|
*/
|
||||||
|
public ENUM_MAP(T[] keys, VALUE_TYPE[] values) {
|
||||||
|
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||||
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
|
keyType = keys[0].getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
|
putAll(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map.
|
||||||
|
* @param map the values that should be present in the map
|
||||||
|
*/
|
||||||
|
public ENUM_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||||
|
if(map instanceof ENUM_MAP) {
|
||||||
|
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
size = enumMap.size;
|
||||||
|
}
|
||||||
|
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||||
|
else {
|
||||||
|
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||||
|
present = new long[((keys.length - 1) >> 6) + 1];
|
||||||
|
putAll(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map.
|
||||||
|
* @param map the values that should be present in the map
|
||||||
|
*/
|
||||||
|
public ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
|
if(map instanceof ENUM_MAP) {
|
||||||
|
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
size = enumMap.size;
|
||||||
|
}
|
||||||
|
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||||
|
else {
|
||||||
|
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||||
|
present = new long[((keys.length - 1) >> 6) + 1];
|
||||||
|
putAll(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE put(T key, VALUE_TYPE value) {
|
public VALUE_TYPE put(T key, VALUE_TYPE value) {
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
@@ -91,9 +181,22 @@ 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) {
|
||||||
|
if(!keyType.isInstance(key)) return false;
|
||||||
return isSet(((T)key).ordinal());
|
return isSet(((T)key).ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +204,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
for(int i = 0;i<values.length;i++)
|
for(int i = 0;i<values.length;i++)
|
||||||
if(VALUE_EQUALS(value, values[i])) return true;
|
if(isSet(i) && VALUE_EQUALS(value, values[i])) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +212,25 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
@Override
|
@Override
|
||||||
public boolean containsValue(VALUE_TYPE value) {
|
public boolean containsValue(VALUE_TYPE value) {
|
||||||
for(int i = 0;i<values.length;i++)
|
for(int i = 0;i<values.length;i++)
|
||||||
if(VALUE_EQUALS(value, values[i])) return true;
|
if(isSet(i) && VALUE_EQUALS(value, values[i])) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@Override
|
||||||
|
public CLASS_VALUE_TYPE remove(Object key) {
|
||||||
|
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||||
|
int index = ((T)key).ordinal();
|
||||||
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
|
clear(index);
|
||||||
|
VALUE_TYPE result = values[index];
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE rem(T key) {
|
public VALUE_TYPE rem(T key) {
|
||||||
|
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
if(!isSet(index)) return getDefaultReturnValue();
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
clear(index);
|
clear(index);
|
||||||
@@ -157,6 +272,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE GET_VALUE(T key) {
|
public VALUE_TYPE GET_VALUE(T key) {
|
||||||
|
if(!keyType.isInstance(key)) return getDefaultReturnValue();
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
return isSet(index) ? values[index] : getDefaultReturnValue();
|
return isSet(index) ? values[index] : getDefaultReturnValue();
|
||||||
}
|
}
|
||||||
@@ -164,6 +280,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
#if VALUE_OBJECT
|
#if VALUE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
|
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
|
||||||
|
if(!keyType.isInstance(key)) return defaultValue;
|
||||||
int index = ((T)key).ordinal();
|
int index = ((T)key).ordinal();
|
||||||
return isSet(index) ? values[index] : defaultValue;
|
return isSet(index) ? values[index] : defaultValue;
|
||||||
}
|
}
|
||||||
@@ -171,6 +288,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
#else
|
#else
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getOrDefault(T key, VALUE_TYPE defaultValue) {
|
public VALUE_TYPE getOrDefault(T key, VALUE_TYPE defaultValue) {
|
||||||
|
if(!keyType.isInstance(key)) return defaultValue;
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
return isSet(index) ? values[index] : defaultValue;
|
return isSet(index) ? values[index] : defaultValue;
|
||||||
}
|
}
|
||||||
@@ -203,6 +321,145 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
return valuesC;
|
return valuesC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||||
|
if(size() <= 0) return;
|
||||||
|
for(int i = 0,m=keys.length;i<m;i++) {
|
||||||
|
if(isSet(i)) action.accept(keys[i], values[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean replace(T key, VALUE_TYPE oldValue, VALUE_TYPE newValue) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index) || values[index] != oldValue) return false;
|
||||||
|
values[index] = newValue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE replace(T key, VALUE_TYPE value) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index)) return getDefaultReturnValue();
|
||||||
|
VALUE_TYPE oldValue = values[index];
|
||||||
|
values[index] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index)) {
|
||||||
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
set(index);
|
||||||
|
values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
clear(index);
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_ABSENT(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index)) {
|
||||||
|
VALUE_TYPE newValue = mappingFunction.GET_VALUE(key);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
set(index);
|
||||||
|
values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = mappingFunction.GET_VALUE(key);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index)) {
|
||||||
|
VALUE_TYPE newValue = valueProvider.VALUE_GET_KEY();
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
set(index);
|
||||||
|
values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
VALUE_TYPE newValue = values[index];
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
newValue = valueProvider.VALUE_GET_KEY();
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||||
|
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
clear(index);
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE MERGE(T key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
int index = key.ordinal();
|
||||||
|
#if VALUE_OBJECT
|
||||||
|
Objects.requireNonNull(value);
|
||||||
|
#endif
|
||||||
|
VALUE_TYPE newValue = !isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? value : mappingFunction.APPLY_VALUE(values[index], value);
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
if(isSet(index)) {
|
||||||
|
clear(index);
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!isSet(index)) {
|
||||||
|
set(index);
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
else values[index] = newValue;
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||||
|
Objects.requireNonNull(mappingFunction);
|
||||||
|
for(MAP.Entry KEY_VALUE_GENERIC_TYPE entry : MAPS.fastIterable(m)) {
|
||||||
|
T key = entry.ENTRY_KEY();
|
||||||
|
int index = key.ordinal();
|
||||||
|
VALUE_TYPE newValue = !isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue()) ? entry.ENTRY_VALUE() : mappingFunction.APPLY_VALUE(values[index], entry.ENTRY_VALUE());
|
||||||
|
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||||
|
if(isSet(index)) {
|
||||||
|
clear(index);
|
||||||
|
values[index] = EMPTY_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!isSet(index)) {
|
||||||
|
set(index);
|
||||||
|
values[index] = newValue;
|
||||||
|
}
|
||||||
|
else values[index] = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if(size == 0) return;
|
if(size == 0) return;
|
||||||
@@ -211,6 +468,11 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
Arrays.fill(values, EMPTY_VALUE);
|
Arrays.fill(values, EMPTY_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
protected void onNodeAdded(int index) {
|
protected void onNodeAdded(int index) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -220,16 +482,18 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void set(int index) {
|
protected void set(int index) {
|
||||||
present[index >> 6] |= (1L << index);
|
|
||||||
onNodeAdded(index);
|
onNodeAdded(index);
|
||||||
|
present[index >> 6] |= (1L << index);
|
||||||
|
size++;
|
||||||
}
|
}
|
||||||
protected void clear(int index) {
|
protected void clear(int index) {
|
||||||
|
size--;
|
||||||
present[index >> 6] &= ~(1L << index);
|
present[index >> 6] &= ~(1L << index);
|
||||||
onNodeRemoved(index);
|
onNodeRemoved(index);
|
||||||
}
|
}
|
||||||
protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; }
|
protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; }
|
||||||
|
|
||||||
private static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
|
protected static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
|
||||||
return keyType.getEnumConstants();
|
return keyType.getEnumConstants();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +501,20 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) return containsKey(((Map.Entry<?, ?>)o).getKey());
|
if(o instanceof Map.Entry) {
|
||||||
|
if(o instanceof MAP.Entry) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
if(!keyType.isInstance(entry.ENTRY_KEY())) return false;
|
||||||
|
int index = ((T)entry.ENTRY_KEY()).ordinal();
|
||||||
|
if(index >= 0 && ENUM_MAP.this.isSet(index)) return VALUE_EQUALS(entry.ENTRY_VALUE(), ENUM_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
if(!keyType.isInstance(entry.getKey())) return false;
|
||||||
|
int index = ((T)entry.getKey()).ordinal();
|
||||||
|
if(index >= 0 && ENUM_MAP.this.isSet(index)) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(ENUM_MAP.this.values[index]));
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,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();
|
||||||
@@ -333,8 +618,7 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
class EntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
class EntryIterator extends MapIterator implements ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||||
int index = nextEntry();
|
return new MapEntry(nextEntry());
|
||||||
return new BasicEntry<>(keys[index], values[index]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,13 +653,74 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
|||||||
public int nextEntry() {
|
public int nextEntry() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturnValue = nextIndex;
|
lastReturnValue = nextIndex;
|
||||||
return nextIndex;
|
nextIndex = -1;
|
||||||
|
return lastReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturnValue == -1) throw new IllegalStateException();
|
if(lastReturnValue == -1) throw new IllegalStateException();
|
||||||
clear(lastReturnValue);
|
clear(lastReturnValue);
|
||||||
values[lastReturnValue] = EMPTY_VALUE;
|
values[lastReturnValue] = EMPTY_VALUE;
|
||||||
|
lastReturnValue = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class MapEntry implements MAP.Entry KEY_VALUE_GENERIC_TYPE, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> {
|
||||||
|
public int index = -1;
|
||||||
|
|
||||||
|
public MapEntry() {}
|
||||||
|
public MapEntry(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE ENTRY_KEY() {
|
||||||
|
return keys[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE ENTRY_VALUE() {
|
||||||
|
return values[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VALUE_TYPE setValue(VALUE_TYPE value) {
|
||||||
|
VALUE_TYPE oldValue = values[index];
|
||||||
|
values[index] = value;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(obj instanceof Map.Entry) {
|
||||||
|
if(obj instanceof MAP.Entry) {
|
||||||
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)obj;
|
||||||
|
return KEY_EQUALS(keys[index], entry.ENTRY_KEY()) && VALUE_EQUALS(values[index], entry.ENTRY_VALUE());
|
||||||
|
}
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||||
|
Object key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
#if TYPE_OBJECT && VALUE_OBJECT
|
||||||
|
return KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], value);
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
return value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], key) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||||
|
#else if VALUE_OBJECT
|
||||||
|
return key instanceof CLASS_TYPE && KEY_EQUALS(keys[index], CLASS_TO_KEY(key)) && VALUE_EQUALS(values[index], value);
|
||||||
|
#else
|
||||||
|
return key instanceof CLASS_TYPE && value instanceof CLASS_VALUE_TYPE && KEY_EQUALS(keys[index], CLASS_TO_KEY(key)) && VALUE_EQUALS(values[index], CLASS_TO_VALUE(value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return KEY_TO_HASH(keys[index]) ^ VALUE_TO_HASH(values[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+160
-57
@@ -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;
|
||||||
@@ -59,6 +54,136 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
links = new long[keys.length];
|
links = new long[keys.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !VALUE_OBJECT
|
||||||
|
/**
|
||||||
|
* Helper constructor that allow to create a EnumMap from boxed values (it will unbox them)
|
||||||
|
* @param keys the keys that should be put into the EnumMap
|
||||||
|
* @param values the values that should be put into the EnumMap.
|
||||||
|
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||||
|
*/
|
||||||
|
public LINKED_ENUM_MAP(T[] keys, CLASS_VALUE_TYPE[] values) {
|
||||||
|
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||||
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
|
keyType = keys[0].getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
|
links = new long[this.keys.length];
|
||||||
|
putAll(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* Helper constructor that allow to create a EnumMap from unboxed values
|
||||||
|
* @param keys the keys that should be put into the map
|
||||||
|
* @param values the values that should be put into the map.
|
||||||
|
* @throws IllegalStateException if the keys and values do not match in lenght
|
||||||
|
*/
|
||||||
|
public LINKED_ENUM_MAP(T[] keys, VALUE_TYPE[] values) {
|
||||||
|
if(keys.length <= 0) throw new IllegalArgumentException("Empty Array are not allowed");
|
||||||
|
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||||
|
keyType = keys[0].getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||||
|
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||||
|
links = new long[this.keys.length];
|
||||||
|
putAll(keys, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper constructor that allows to create a EnumMap with exactly the same values as the provided map.
|
||||||
|
* @param map the values that should be present in the map
|
||||||
|
*/
|
||||||
|
public LINKED_ENUM_MAP(Map<? extends CLASS_TYPE, ? extends CLASS_VALUE_TYPE> map) {
|
||||||
|
if(map instanceof LINKED_ENUM_MAP) {
|
||||||
|
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
links = enumMap.links.clone();
|
||||||
|
size = enumMap.size;
|
||||||
|
}
|
||||||
|
else if(map instanceof ENUM_MAP) {
|
||||||
|
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
links = new long[keys.length];
|
||||||
|
for(int i = 0,m=keys.length;i<m;i++) {
|
||||||
|
if(isSet(i)) {
|
||||||
|
if(size == 0) {
|
||||||
|
firstIndex = lastIndex = i;
|
||||||
|
links[i] = -1L;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
links[lastIndex] ^= ((links[lastIndex] ^ (i & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
links[i] = ((lastIndex & 0xFFFFFFFFL) << 32) | 0xFFFFFFFFL;
|
||||||
|
lastIndex = i;
|
||||||
|
}
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||||
|
else {
|
||||||
|
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||||
|
present = new long[((keys.length - 1) >> 6) + 1];
|
||||||
|
links = new long[keys.length];
|
||||||
|
putAll(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Type Specific Helper function that allows to create a new EnumMap with exactly the same values as the provided map.
|
||||||
|
* @param map the values that should be present in the map
|
||||||
|
*/
|
||||||
|
public LINKED_ENUM_MAP(MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||||
|
if(map instanceof LINKED_ENUM_MAP) {
|
||||||
|
LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (LINKED_ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
links = enumMap.links.clone();
|
||||||
|
size = enumMap.size;
|
||||||
|
}
|
||||||
|
else if(map instanceof ENUM_MAP) {
|
||||||
|
ENUM_MAP KEY_VALUE_GENERIC_TYPE enumMap = (ENUM_MAP KEY_VALUE_GENERIC_TYPE)map;
|
||||||
|
keyType = enumMap.keyType;
|
||||||
|
keys = enumMap.keys;
|
||||||
|
values = enumMap.values.clone();
|
||||||
|
present = enumMap.present.clone();
|
||||||
|
links = new long[keys.length];
|
||||||
|
for(int i = 0,m=keys.length;i<m;i++) {
|
||||||
|
if(isSet(i)) {
|
||||||
|
if(size == 0) {
|
||||||
|
firstIndex = lastIndex = i;
|
||||||
|
links[i] = -1L;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
links[lastIndex] ^= ((links[lastIndex] ^ (i & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
links[i] = ((lastIndex & 0xFFFFFFFFL) << 32) | 0xFFFFFFFFL;
|
||||||
|
lastIndex = i;
|
||||||
|
}
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(map.isEmpty()) throw new IllegalArgumentException("Empty Maps are not allowed");
|
||||||
|
else {
|
||||||
|
keyType = map.keySet().iterator().next().getDeclaringClass();
|
||||||
|
this.keys = getKeyUniverse(keyType);
|
||||||
|
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||||
|
present = new long[((keys.length - 1) >> 6) + 1];
|
||||||
|
links = new long[keys.length];
|
||||||
|
putAll(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE putAndMoveToFirst(T key, VALUE_TYPE value) {
|
public VALUE_TYPE putAndMoveToFirst(T key, VALUE_TYPE value) {
|
||||||
int index = key.ordinal();
|
int index = key.ordinal();
|
||||||
@@ -114,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];
|
||||||
}
|
}
|
||||||
@@ -122,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];
|
||||||
}
|
}
|
||||||
@@ -139,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();
|
||||||
@@ -202,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
|
||||||
@@ -303,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
|
||||||
@@ -389,8 +500,18 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean contains(Object o) {
|
public boolean contains(Object o) {
|
||||||
if(o instanceof Map.Entry) {
|
if(o instanceof Map.Entry) {
|
||||||
if(o instanceof MAP.Entry) return LINKED_ENUM_MAP.this.containsKey(((MAP.Entry KEY_VALUE_GENERIC_TYPE)o).ENTRY_KEY());
|
if(o instanceof MAP.Entry) {
|
||||||
return LINKED_ENUM_MAP.this.containsKey(((Map.Entry<?, ?>)o).getKey());
|
MAP.Entry KEY_VALUE_GENERIC_TYPE entry = (MAP.Entry KEY_VALUE_GENERIC_TYPE)o;
|
||||||
|
if(!keyType.isInstance(entry.ENTRY_KEY())) return false;
|
||||||
|
int index = ((T)entry.ENTRY_KEY()).ordinal();
|
||||||
|
if(index >= 0 && LINKED_ENUM_MAP.this.isSet(index)) return VALUE_EQUALS(entry.ENTRY_VALUE(), LINKED_ENUM_MAP.this.values[index]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)o;
|
||||||
|
if(!keyType.isInstance(entry.getKey())) return false;
|
||||||
|
int index = ((T)entry.getKey()).ordinal();
|
||||||
|
if(index >= 0 && LINKED_ENUM_MAP.this.isSet(index)) return Objects.equals(entry.getValue(), VALUE_TO_OBJ(LINKED_ENUM_MAP.this.values[index]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -418,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
|
||||||
@@ -442,7 +552,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(Object o) {
|
public boolean remove(Object o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_ENUM_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +565,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
@Override
|
@Override
|
||||||
public boolean remove(T o) {
|
public boolean remove(T o) {
|
||||||
int oldSize = size;
|
int oldSize = size;
|
||||||
remove(o);
|
LINKED_ENUM_MAP.this.remove(o);
|
||||||
return size != oldSize;
|
return size != oldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,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 {
|
||||||
@@ -729,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() {
|
||||||
@@ -757,6 +857,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
previous = (int)(links[current] >>> 32);
|
previous = (int)(links[current] >>> 32);
|
||||||
}
|
}
|
||||||
else next = (int)links[current];
|
else next = (int)links[current];
|
||||||
|
|
||||||
size--;
|
size--;
|
||||||
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);
|
||||||
@@ -764,6 +865,8 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
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);
|
||||||
values[current] = EMPTY_VALUE;
|
values[current] = EMPTY_VALUE;
|
||||||
|
present[current >> 6] &= ~(1L << current);
|
||||||
|
current = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int previousEntry() {
|
public int previousEntry() {
|
||||||
@@ -855,7 +958,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return KEY_TO_STRING(keys[index]) + "->" + VALUE_TO_STRING(values[index]);
|
return KEY_TO_STRING(keys[index]) + "=" + VALUE_TO_STRING(values[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1570
-1139
File diff suppressed because it is too large
Load Diff
+1592
-1160
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+622
-56
File diff suppressed because it is too large
Load Diff
+29
-4
@@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.maps.interfaces;
|
|||||||
|
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Navigable Map interface with a couple helper methods
|
* A Type Specific Navigable Map interface with a couple helper methods
|
||||||
@@ -33,6 +34,30 @@ 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
|
||||||
|
* @return a new NavigableMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new NavigableMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableMap that is unmodifiable
|
||||||
|
* @return a new NavigableMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
@@ -184,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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
-56
@@ -9,8 +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;
|
||||||
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,60 +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();
|
||||||
|
|
||||||
@@ -79,10 +33,32 @@ 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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @return a new SortedMap that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedMap Wrapper that is synchronized
|
||||||
|
* @see MAPS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedMap that is unmodifiable
|
||||||
|
* @return a new SortedMap Wrapper that is unmodifiable
|
||||||
|
* @see MAPS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type Specific SubMap method to reduce boxing/unboxing
|
* A Type Specific SubMap method to reduce boxing/unboxing
|
||||||
@@ -181,11 +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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+54
-6
@@ -4,6 +4,7 @@ import java.util.Arrays;
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@@ -15,6 +16,7 @@ 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;
|
||||||
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.utils.ITrimmable;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,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;
|
||||||
}
|
}
|
||||||
@@ -150,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
|
||||||
@@ -299,6 +307,45 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0,m=size();i<m;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[(first + i) % array.length];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[(first + i) % array.length]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -387,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;
|
||||||
|
|||||||
+44
-2
@@ -5,6 +5,7 @@ import java.util.NoSuchElementException;
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -16,7 +17,9 @@ 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;
|
||||||
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.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
|
||||||
@@ -68,7 +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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,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;
|
||||||
@@ -294,6 +296,45 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -373,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-2
@@ -5,6 +5,7 @@ import java.util.NoSuchElementException;
|
|||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -16,7 +17,9 @@ 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;
|
||||||
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.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Simple Heap base Priority Queue implementation
|
* A Simple Heap base Priority Queue implementation
|
||||||
@@ -64,7 +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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,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);
|
||||||
}
|
}
|
||||||
@@ -281,6 +283,45 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = array[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, array[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -348,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -6,6 +6,7 @@ import java.util.Iterator;
|
|||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
||||||
@@ -80,6 +81,21 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE
|
|||||||
*/
|
*/
|
||||||
public default KEY_TYPE last() { return peek(size()-1); }
|
public default KEY_TYPE last() { return peek(size()-1); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||||
|
* @return a new PriorityDequeue that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new PriorityDequeue Wrapper that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
||||||
}
|
}
|
||||||
+31
@@ -4,12 +4,16 @@ package speiger.src.collections.PACKAGE.queues;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||||
#else
|
#else
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
|
||||||
@@ -144,6 +148,22 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
|||||||
*/
|
*/
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator();
|
public ITERATOR KEY_GENERIC_TYPE iterator();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
|
* @return a new PriorityQueue that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped PriorityQueue that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new PriorityQueue Wrapper that is synchronized
|
||||||
|
* @see PRIORITY_QUEUES#synchronize
|
||||||
|
*/
|
||||||
|
public default PRIORITY_QUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method to drop the contents of the Queue without clearing the queue
|
* A method to drop the contents of the Queue without clearing the queue
|
||||||
* @Type(E)
|
* @Type(E)
|
||||||
@@ -158,4 +178,15 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
|||||||
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
* @note if the Type is generic then a Object Array is created instead of a Type Array
|
||||||
*/
|
*/
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
/**
|
||||||
|
* A Helper function that simplifies the process of creating a new Array.
|
||||||
|
* @param action the array creation function
|
||||||
|
* @return an array containing all of the elements in this collection
|
||||||
|
* @see Collection#toArray(Object[])
|
||||||
|
*/
|
||||||
|
default KEY_TYPE[] TO_ARRAY(Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||||
|
return TO_ARRAY(action.get(size()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
+625
-355
File diff suppressed because it is too large
Load Diff
+12
-20
@@ -1,7 +1,8 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
import java.util.Iterator;
|
#if TYPE_OBJECT
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
#endif
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||||
@@ -13,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
|
||||||
@@ -20,10 +26,10 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = 1;
|
int hashCode = 0;
|
||||||
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
ITERATOR KEY_GENERIC_TYPE i = iterator();
|
||||||
while(i.hasNext())
|
while(i.hasNext())
|
||||||
hashCode = 31 * hashCode + KEY_TO_HASH(i.NEXT());
|
hashCode += KEY_TO_HASH(i.NEXT());
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,24 +41,10 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
|||||||
return false;
|
return false;
|
||||||
Set<?> l = (Set<?>)o;
|
Set<?> l = (Set<?>)o;
|
||||||
if(l.size() != size()) return false;
|
if(l.size() != size()) return false;
|
||||||
#if !TYPE_OBJECT
|
try {
|
||||||
if(l instanceof SET)
|
return containsAll(l);
|
||||||
{
|
} catch (ClassCastException | NullPointerException unused) {
|
||||||
ITERATOR e1 = iterator();
|
|
||||||
ITERATOR e2 = ((SET)l).iterator();
|
|
||||||
while (e1.hasNext() && e2.hasNext()) {
|
|
||||||
if(!(KEY_EQUALS(e1.NEXT(), e2.NEXT())))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !(e1.hasNext() || e2.hasNext());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Iterator<CLASS_TYPE> e1 = iterator();
|
|
||||||
Iterator<?> e2 = l.iterator();
|
|
||||||
while (e1.hasNext() && e2.hasNext()) {
|
|
||||||
if(!Objects.equals(e1.next(), e2.next()))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !(e1.hasNext() || e2.hasNext());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+98
-378
@@ -3,8 +3,8 @@ package speiger.src.collections.PACKAGE.sets;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -18,8 +18,8 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|||||||
|
|
||||||
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;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
|
||||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
#endif
|
#endif
|
||||||
@@ -34,7 +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;
|
||||||
@@ -54,6 +54,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
* @throws NegativeArraySizeException if the capacity is negative
|
* @throws NegativeArraySizeException if the capacity is negative
|
||||||
*/
|
*/
|
||||||
public ARRAY_SET(int capacity) {
|
public ARRAY_SET(int capacity) {
|
||||||
|
if(capacity < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||||
data = NEW_KEY_ARRAY(capacity);
|
data = NEW_KEY_ARRAY(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +73,8 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
* @throws NegativeArraySizeException if the length is negative
|
* @throws NegativeArraySizeException if the length is negative
|
||||||
*/
|
*/
|
||||||
public ARRAY_SET(KEY_TYPE[] array, int length) {
|
public ARRAY_SET(KEY_TYPE[] array, int length) {
|
||||||
data = Arrays.copyOf(array, length);
|
this(length);
|
||||||
size = length;
|
addAll(array, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,6 +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);
|
||||||
@@ -157,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;
|
||||||
@@ -227,6 +239,21 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(!c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean result = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@@ -242,6 +269,21 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) {
|
||||||
|
int j = 0;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(c.contains(data[i])) data[j++] = data[i];
|
||||||
|
else r.accept(data[i]);
|
||||||
|
}
|
||||||
|
boolean result = j != size;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
Arrays.fill(data, j, size, null);
|
||||||
|
#endif
|
||||||
|
size = j;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public boolean removeAll(Collection<?> c) {
|
public boolean removeAll(Collection<?> c) {
|
||||||
@@ -392,6 +434,45 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
return EMPTY_VALUE;
|
return EMPTY_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
for(int i = 0;i<size;i++) {
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = data[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, data[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
public int count(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -428,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);
|
||||||
@@ -457,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;
|
||||||
@@ -477,6 +531,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||||
if(a == null || a.length < size()) return Arrays.copyOf(data, size());
|
if(a == null || a.length < size()) return Arrays.copyOf(data, size());
|
||||||
System.arraycopy(data, 0, a, 0, size());
|
System.arraycopy(data, 0, a, 0, size());
|
||||||
|
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,264 +552,10 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||||
for(int i = 0;i<size();i++)
|
for(int i = 0;i<size();i++)
|
||||||
a[i] = (E)KEY_TO_OBJ(data[i]);
|
a[i] = (E)KEY_TO_OBJ(data[i]);
|
||||||
|
if (a.length > size) a[size] = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
|
||||||
int offset;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
SubSet(int offset, int length) {
|
|
||||||
this.offset = offset;
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
int end() { return offset+length; }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean add(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
|
|
||||||
data[end()] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
System.arraycopy(data, offset, data, offset+1, size-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(index != 0) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index == -1) {
|
|
||||||
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
|
||||||
System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
data[end()] = o;
|
|
||||||
size++;
|
|
||||||
length++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(index != 0) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset+1, data, offset, index-offset);
|
|
||||||
data[offset+length] = o;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToFirst(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index > offset) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, offset, data, offset+1, index-offset);
|
|
||||||
data[offset] = o;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean moveToLast(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1 && index < end()-1) {
|
|
||||||
o = data[index];
|
|
||||||
System.arraycopy(data, index+1, data, index, end()-index-1);
|
|
||||||
data[end()-1] = o;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public boolean contains(KEY_TYPE e) {
|
|
||||||
return findIndex(e) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
public boolean contains(Object e) {
|
|
||||||
return findIndex(e) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE FIRST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
return data[offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE LAST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
return data[end()-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public boolean remove(KEY_TYPE o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1) {
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
public boolean remove(Object o) {
|
|
||||||
int index = findIndex(o);
|
|
||||||
if(index != -1) {
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE POLL_FIRST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
KEY_TYPE result = data[offset];
|
|
||||||
System.arraycopy(data, offset+1, data, offset, size-offset);
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE POLL_LAST_KEY() {
|
|
||||||
if(length == 0) throw new NoSuchElementException();
|
|
||||||
KEY_TYPE result = data[offset+length];
|
|
||||||
size--;
|
|
||||||
length--;
|
|
||||||
System.arraycopy(data, end()+1, data, end(), size-end());
|
|
||||||
#if TYPE_OBJECT
|
|
||||||
data[size] = EMPTY_KEY_VALUE;
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
|
||||||
return new SetIterator(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
|
||||||
int index = findIndex(fromElement);
|
|
||||||
if(index != -1) return new SetIterator(index);
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubSet copy() { throw new UnsupportedOperationException(); }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
|
||||||
int toIndex = findIndex(toElement);
|
|
||||||
if(toIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(0, toIndex+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
|
||||||
int fromIndex = findIndex(fromElement);
|
|
||||||
if(fromIndex == -1) throw new NoSuchElementException();
|
|
||||||
return new SubSet(fromIndex, size - fromIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
|
||||||
if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
|
|
||||||
System.arraycopy(data, offset, a, 0, size());
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public Object[] toArray() {
|
|
||||||
Object[] obj = new Object[size()];
|
|
||||||
for(int i = 0;i<size();i++)
|
|
||||||
obj[i] = KEY_TO_OBJ(data[offset+i]);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Primitive
|
|
||||||
public <E> E[] toArray(E[] a) {
|
|
||||||
if(a == null) a = (E[])new Object[size()];
|
|
||||||
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
|
||||||
for(int i = 0;i<size();i++)
|
|
||||||
a[i] = (E)KEY_TO_OBJ(data[offset+i]);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
|
||||||
protected int findIndex(KEY_TYPE o) {
|
|
||||||
for(int i = length-1;i>=0;i--)
|
|
||||||
if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
protected int findIndex(Object o) {
|
|
||||||
for(int i = length-1;i>=0;i--)
|
|
||||||
if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||||
int index;
|
int index;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
@@ -770,6 +571,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
lastReturned = index;
|
lastReturned = index;
|
||||||
return data[index++];
|
return data[index++];
|
||||||
}
|
}
|
||||||
@@ -781,8 +583,9 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE PREVIOUS() {
|
public KEY_TYPE PREVIOUS() {
|
||||||
lastReturned = index;
|
if(!hasPrevious()) throw new NoSuchElementException();
|
||||||
return data[index--];
|
--index;
|
||||||
|
return data[(lastReturned = index)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -797,94 +600,9 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if(lastReturned == -1)
|
if(lastReturned == -1) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
|
||||||
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() {
|
|
||||||
lastReturned = index;
|
|
||||||
return data[index++];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPrevious() {
|
|
||||||
return index > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KEY_TYPE PREVIOUS() {
|
|
||||||
lastReturned = index;
|
|
||||||
return data[index--];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int nextIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int previousIndex() {
|
|
||||||
return index-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
if(lastReturned == -1)
|
|
||||||
throw new IllegalStateException();
|
|
||||||
ARRAY_SET.this.remove(data[lastReturned]);
|
ARRAY_SET.this.remove(data[lastReturned]);
|
||||||
if(lastReturned < index)
|
if(lastReturned < index) index--;
|
||||||
index--;
|
|
||||||
lastReturned = -1;
|
lastReturned = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,8 +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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-22
@@ -1,8 +1,8 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -14,11 +14,11 @@ 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;
|
||||||
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.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -32,7 +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;
|
||||||
@@ -188,7 +188,18 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
{
|
{
|
||||||
KEY_TYPE o = a[i];
|
KEY_TYPE o = a[i];
|
||||||
if(KEY_EQUALS_NULL(o)) {
|
if(KEY_EQUALS_NULL(o)) {
|
||||||
if(!containsNull) size++;
|
if(!containsNull) {
|
||||||
|
size++;
|
||||||
|
if(prev != -1) {
|
||||||
|
newLinks[prev] ^= ((newLinks[prev] ^ (newSize & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||||
|
newLinks[newSize] ^= ((newLinks[newSize] ^ ((prev & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||||
|
prev = newSize;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev = firstIndex = newSize;
|
||||||
|
newLinks[newSize] = -1L;
|
||||||
|
}
|
||||||
|
}
|
||||||
containsNull = true;
|
containsNull = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -197,7 +208,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
KEY_TYPE current = newKeys[pos];
|
KEY_TYPE current = newKeys[pos];
|
||||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||||
if(KEY_EQUALS(current, o)) continue;
|
if(KEY_EQUALS(current, o)) continue;
|
||||||
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & mask)]))) {
|
while(KEY_EQUALS_NOT_NULL((current = newKeys[pos = (++pos & newMask)]))) {
|
||||||
if(KEY_EQUALS(current, o)) {
|
if(KEY_EQUALS(current, o)) {
|
||||||
found = false;
|
found = false;
|
||||||
break;
|
break;
|
||||||
@@ -218,7 +229,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nullIndex = size;
|
nullIndex = newSize;
|
||||||
mask = newMask;
|
mask = newMask;
|
||||||
keys = newKeys;
|
keys = newKeys;
|
||||||
links = newLinks;
|
links = newLinks;
|
||||||
@@ -228,6 +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(); }
|
||||||
@@ -244,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;
|
||||||
@@ -346,6 +366,50 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -393,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(); }
|
||||||
|
|
||||||
@@ -450,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;
|
||||||
@@ -478,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];
|
||||||
}
|
}
|
||||||
@@ -488,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+81
-29
@@ -1,8 +1,8 @@
|
|||||||
package speiger.src.collections.PACKAGE.sets;
|
package speiger.src.collections.PACKAGE.sets;
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -15,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;
|
||||||
@@ -25,6 +22,7 @@ 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;
|
||||||
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.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
@@ -35,7 +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;
|
||||||
@@ -125,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]);
|
||||||
}
|
}
|
||||||
@@ -239,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;
|
||||||
@@ -251,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;
|
||||||
@@ -284,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);
|
||||||
@@ -306,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);
|
||||||
@@ -372,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)) {
|
||||||
@@ -395,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)) {
|
||||||
@@ -510,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;
|
||||||
}
|
}
|
||||||
@@ -577,6 +575,50 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -626,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;
|
||||||
@@ -685,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();
|
||||||
@@ -743,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];
|
||||||
}
|
}
|
||||||
@@ -753,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+81
-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;
|
||||||
@@ -10,6 +7,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
@@ -18,11 +16,11 @@ 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;
|
||||||
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.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||||
@@ -36,7 +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;
|
||||||
@@ -112,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]);
|
||||||
}
|
}
|
||||||
@@ -210,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;
|
||||||
@@ -222,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;
|
||||||
@@ -255,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);
|
||||||
@@ -277,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);
|
||||||
@@ -343,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)) {
|
||||||
@@ -366,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)) {
|
||||||
@@ -432,6 +430,50 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
int index = firstIndex;
|
||||||
|
while(index != -1) {
|
||||||
|
if(empty) {
|
||||||
|
state = keys[index];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
else state = operator.APPLY_VALUE(state, keys[index]);
|
||||||
|
index = (int)links[index];
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -557,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;
|
||||||
}
|
}
|
||||||
@@ -597,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;
|
||||||
@@ -646,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;
|
||||||
@@ -714,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];
|
||||||
}
|
}
|
||||||
@@ -724,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];
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-2
@@ -4,6 +4,7 @@ import java.util.NavigableSet;
|
|||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +119,30 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
|||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy();
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is Synchronized
|
||||||
|
* @return a new NavigableSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new NavigableSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped NavigableSet that is unmodifiable
|
||||||
|
* @return a new NavigableSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
@@ -146,10 +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
|
||||||
|
|||||||
+83
-6
@@ -8,6 +8,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
@@ -20,6 +21,7 @@ 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;
|
||||||
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.utils.STRATEGY;
|
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||||
|
|
||||||
import speiger.src.collections.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
@@ -275,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) {
|
||||||
@@ -347,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;
|
||||||
@@ -359,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;
|
||||||
}
|
}
|
||||||
@@ -527,6 +553,54 @@ 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 reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -552,6 +626,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
|
|
||||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
@@ -584,6 +659,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||||
@@ -602,9 +678,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
|||||||
containsNull = false;
|
containsNull = false;
|
||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
CUSTOM_HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
|
|||||||
+93
-6
@@ -8,6 +8,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
@@ -20,6 +21,7 @@ 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;
|
||||||
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.utils.HashUtil;
|
import speiger.src.collections.utils.HashUtil;
|
||||||
import speiger.src.collections.utils.ITrimmable;
|
import speiger.src.collections.utils.ITrimmable;
|
||||||
import speiger.src.collections.utils.SanityChecks;
|
import speiger.src.collections.utils.SanityChecks;
|
||||||
@@ -233,6 +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) {
|
||||||
@@ -250,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;
|
||||||
@@ -263,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;
|
||||||
@@ -304,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;
|
||||||
@@ -316,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;
|
||||||
}
|
}
|
||||||
@@ -380,6 +416,54 @@ 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 reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_SPECIAL_TYPE state = identity;
|
||||||
|
if(containsNull) state = operator.APPLY_VALUE(state, keys[nullIndex]);
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) {
|
||||||
|
Objects.requireNonNull(operator);
|
||||||
|
KEY_TYPE state = EMPTY_VALUE;
|
||||||
|
boolean empty = true;
|
||||||
|
if(containsNull) {
|
||||||
|
state = keys[nullIndex];
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
for(int i = nullIndex-1;i>=0;i--) {
|
||||||
|
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||||
|
if(empty) {
|
||||||
|
empty = false;
|
||||||
|
state = keys[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
state = operator.APPLY_VALUE(state, keys[i]);
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) {
|
||||||
Objects.requireNonNull(filter);
|
Objects.requireNonNull(filter);
|
||||||
@@ -509,6 +593,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
|
|
||||||
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
private class SetIterator implements ITERATOR KEY_GENERIC_TYPE {
|
||||||
int pos = nullIndex;
|
int pos = nullIndex;
|
||||||
|
int returnedPos = -1;
|
||||||
int lastReturned = -1;
|
int lastReturned = -1;
|
||||||
int nextIndex = Integer.MIN_VALUE;
|
int nextIndex = Integer.MIN_VALUE;
|
||||||
boolean returnNull = containsNull;
|
boolean returnNull = containsNull;
|
||||||
@@ -542,6 +627,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE NEXT() {
|
public KEY_TYPE NEXT() {
|
||||||
if(!hasNext()) throw new NoSuchElementException();
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
returnedPos = pos;
|
||||||
if(nextIndex < 0){
|
if(nextIndex < 0){
|
||||||
lastReturned = Integer.MAX_VALUE;
|
lastReturned = Integer.MAX_VALUE;
|
||||||
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
KEY_TYPE value = wrapped.GET_KEY(nextIndex);
|
||||||
@@ -560,9 +646,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
|||||||
containsNull = false;
|
containsNull = false;
|
||||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||||
}
|
}
|
||||||
else if(pos >= 0) shiftKeys(pos);
|
else if(returnedPos >= 0) shiftKeys(returnedPos);
|
||||||
else {
|
else {
|
||||||
HASH_SET.this.remove(wrapped.GET_KEY(-pos - 1));
|
HASH_SET.this.remove(wrapped.GET_KEY(-returnedPos - 1));
|
||||||
|
lastReturned = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size--;
|
size--;
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
+623
-354
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,12 @@ import java.util.Set;
|
|||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
|
#endif
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Set class to reduce boxing/unboxing
|
* A Type Specific Set class to reduce boxing/unboxing
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
@@ -49,6 +53,40 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
|||||||
public default boolean remove(Object o) {
|
public default boolean remove(Object o) {
|
||||||
return COLLECTION.super.remove(o);
|
return COLLECTION.super.remove(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
/**
|
||||||
|
* A Helper method that allows to add a element or getting the already present implement.
|
||||||
|
* Allowing to make unique references reuseable.
|
||||||
|
* @param o the element to add
|
||||||
|
* @return either the inserted element or the present element.
|
||||||
|
*/
|
||||||
|
public KEY_TYPE addOrGet(KEY_TYPE o);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is Synchronized
|
||||||
|
* @return a new Set that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new Set Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped Set that is unmodifiable
|
||||||
|
* @return a new Set Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
|
|||||||
+27
-35
@@ -9,50 +9,18 @@ import java.util.Comparator;
|
|||||||
#else
|
#else
|
||||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||||
#endif
|
#endif
|
||||||
|
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||||
* with a couple extra methods that allow greater control over sets.
|
* with a couple extra methods that allow greater control over sets.
|
||||||
* @Type(T)
|
* @Type(T)
|
||||||
|
* @note ORDERED_SET is only extended until 0.6.0 for Compat reasons.
|
||||||
|
* The supported classes already implement ORDERED_SET directly and will remove SORTED_SET implementations in favor of ORDERED_SET instead
|
||||||
*/
|
*/
|
||||||
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the first index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A customized add method that allows you to insert into the last index.
|
|
||||||
* @param o the element that should be inserted
|
|
||||||
* @return true if it was added
|
|
||||||
* @see java.util.Set#add(Object)
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean addAndMoveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the first index.
|
|
||||||
* @param o that should be moved to the first index
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToFirst(KEY_TYPE o);
|
|
||||||
/**
|
|
||||||
* A specific move method to move a given key to the last index.
|
|
||||||
* @param o that should be moved to the first last
|
|
||||||
* @return true if the value was moved.
|
|
||||||
* @note returns false if the value was not present in the first place
|
|
||||||
* @note some implementations do not support this method
|
|
||||||
*/
|
|
||||||
public boolean moveToLast(KEY_TYPE o);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Type Specific Comparator method
|
* A Type Specific Comparator method
|
||||||
* @return the type specific comparator
|
* @return the type specific comparator
|
||||||
@@ -73,6 +41,30 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
|||||||
*/
|
*/
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||||
|
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is Synchronized
|
||||||
|
* @return a new SortedSet that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE synchronize() { return SETS.synchronize(this); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is Synchronized
|
||||||
|
* @param mutex is the controller of the synchronization block
|
||||||
|
* @return a new SortedSet Wrapper that is synchronized
|
||||||
|
* @see SETS#synchronize
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE synchronize(Object mutex) { return SETS.synchronize(this, mutex); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Wrapped SortedSet that is unmodifiable
|
||||||
|
* @return a new SortedSet Wrapper that is unmodifiable
|
||||||
|
* @see SETS#unmodifiable
|
||||||
|
*/
|
||||||
|
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||||
* @return type specific splititerator
|
* @return type specific splititerator
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
-9
@@ -1,6 +1,9 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
#endif
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
import java.util.function.JAVA_PREDICATE;
|
import java.util.function.JAVA_PREDICATE;
|
||||||
@@ -16,6 +19,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
|||||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||||
#endif
|
#endif
|
||||||
import speiger.src.collections.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.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||||
/**
|
/**
|
||||||
* A Helper class for Collections
|
* A Helper class for Collections
|
||||||
@@ -130,7 +134,7 @@ public class COLLECTIONS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public COLLECTION KEY_GENERIC_TYPE copy() { synchronized(mutex) { return c.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
@@ -148,7 +152,11 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.removeAll(c); } }
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.removeAll(c); } }
|
||||||
@Override
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.removeAll(c, r); } }
|
||||||
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.retainAll(c); } }
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { synchronized(mutex) { return this.c.retainAll(c); } }
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { synchronized(mutex) { return this.c.retainAll(c, r); } }
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public boolean remIf(JAVA_PREDICATE filter){ synchronized(mutex) { return c.remIf(filter); } }
|
public boolean remIf(JAVA_PREDICATE filter){ synchronized(mutex) { return c.remIf(filter); } }
|
||||||
@@ -178,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
|
||||||
@@ -189,6 +200,14 @@ public class COLLECTIONS
|
|||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } }
|
||||||
@Override
|
@Override
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { synchronized(mutex) { return c.reduce(operator); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -238,7 +257,7 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
|
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(c.iterator()); }
|
||||||
@Override
|
@Override
|
||||||
public COLLECTION KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public COLLECTION KEY_GENERIC_TYPE copy() { return c.copy(); }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||||
@@ -258,7 +277,11 @@ public class COLLECTIONS
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
|
public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { throw new UnsupportedOperationException(); }
|
||||||
#if PRIMITIVES
|
#if PRIMITIVES
|
||||||
@Override
|
@Override
|
||||||
public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); }
|
public boolean remIf(JAVA_PREDICATE filter){ throw new UnsupportedOperationException(); }
|
||||||
@@ -288,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
|
||||||
@@ -299,6 +322,14 @@ public class COLLECTIONS
|
|||||||
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
|
public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); }
|
||||||
@Override
|
@Override
|
||||||
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
|
public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); }
|
||||||
|
#if TYPE_OBJECT
|
||||||
|
public <KEY_SPECIAL_TYPE> KEY_SPECIAL_TYPE reduce(KEY_SPECIAL_TYPE identity, BiFunction<KEY_SPECIAL_TYPE, KEY_TYPE, KEY_SPECIAL_TYPE> operator) { return c.reduce(identity, operator); }
|
||||||
|
#else
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(KEY_TYPE identity, UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(identity, operator); }
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE reduce(UNARY_OPERATOR KEY_KEY_GENERIC_TYPE operator) { return c.reduce(operator); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); }
|
||||||
@Override
|
@Override
|
||||||
@@ -322,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
|
||||||
@@ -334,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; }
|
||||||
|
|
||||||
@@ -373,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(); }
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
package speiger.src.collections.PACKAGE.utils;
|
package speiger.src.collections.PACKAGE.utils;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
#else if TYPE_OBJECT
|
||||||
|
import java.util.Comparator;
|
||||||
|
#endif
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
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.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
|
||||||
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper class for Iterables
|
* A Helper class for Iterables
|
||||||
@@ -110,6 +127,94 @@ public class ITERABLES
|
|||||||
return new FilteredIterableBRACES(iterable, filter);
|
return new FilteredIterableBRACES(iterable, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that filters out all duplicated elements.
|
||||||
|
* @param iterable that should be distinct
|
||||||
|
* @Type(T)
|
||||||
|
* @return a distinct iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||||
|
return new DistinctIterableBRACES(iterable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that filters out all duplicated elements from a Java Iterable.
|
||||||
|
* @param iterable that should be distinct
|
||||||
|
* @Type(T)
|
||||||
|
* @return a distinct iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE distinct(Iterable<? extends CLASS_TYPE> iterable) {
|
||||||
|
return new DistinctIterableBRACES(wrap(iterable));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that hard limits the Iterable to a specific size
|
||||||
|
* @param iterable that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @Type(T)
|
||||||
|
* @return a limited iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||||
|
return new LimitedIterableBRACES(iterable, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that hard limits the Iterable to a specific size from a Java Iterable
|
||||||
|
* @param iterable that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @Type(T)
|
||||||
|
* @return a limited iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE limit(Iterable<? extends CLASS_TYPE> iterable, long 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.
|
||||||
|
* @param iterable that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterable returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIterableBRACES(iterable, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that allows to preview the result of a Iterable from a Java Iterable
|
||||||
|
* @param iterable that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterable returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterable
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE peek(Iterable<? extends CLASS_TYPE> iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIterableBRACES(wrap(iterable), action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
||||||
* @param iterable that should be wrapped
|
* @param iterable that should be wrapped
|
||||||
@@ -131,6 +236,19 @@ public class ITERABLES
|
|||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
return ITERATORS.wrap(iterable.iterator());
|
return ITERATORS.wrap(iterable.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(action);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(action);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||||
@@ -146,6 +264,12 @@ public class ITERABLES
|
|||||||
public ObjectIterator<T> iterator() {
|
public ObjectIterator<T> iterator() {
|
||||||
return ITERATORS.map(iterable.iterator(), mapper);
|
return ITERATORS.map(iterable.iterator(), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> action.accept(mapper.GET_VALUE(E)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FlatMappedIterable KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterable<T>
|
private static class FlatMappedIterable KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterable<T>
|
||||||
@@ -162,6 +286,13 @@ public class ITERABLES
|
|||||||
public ObjectIterator<T> iterator() {
|
public ObjectIterator<T> iterator() {
|
||||||
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> mapper.GET_VALUE(E).forEach(action));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FlatMappedArrayIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
private static class FlatMappedArrayIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||||
@@ -178,6 +309,15 @@ public class ITERABLES
|
|||||||
public ObjectIterator<T> iterator() {
|
public ObjectIterator<T> iterator() {
|
||||||
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(E -> {
|
||||||
|
T[] array = mapper.GET_VALUE(E);
|
||||||
|
for(int i = 0,m=array.length;i<m;action.accept(array[i++]));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
private static class FilteredIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
@@ -194,5 +334,160 @@ public class ITERABLES
|
|||||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
return ITERATORS.filter(iterable.iterator(), filter);
|
return ITERATORS.filter(iterable.iterator(), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(T -> { if(!filter.TEST_VALUE(T)) action.accept(T); } );
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(T -> { if(!filter.TEST_VALUE(T)) action.accept(T); } );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class LimitedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
long limit;
|
||||||
|
|
||||||
|
public LimitedIterable(ITERABLE KEY_GENERIC_TYPE iterable, long limit) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.limit(iterable.iterator(), limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
AtomicLong counter = new AtomicLong();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(counter.get() >= limit) return;
|
||||||
|
counter.incrementAndGet();
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
AtomicLong counter = new AtomicLong();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(counter.get() >= limit) return;
|
||||||
|
counter.incrementAndGet();
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
|
||||||
|
public DistinctIterable(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.distinct(iterable.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
AtomicInteger result = new AtomicInteger();
|
||||||
|
iterable.forEach(T -> {
|
||||||
|
if(((result.get() & (T ? 2 : 1)) != 0)) return;
|
||||||
|
result.getAndAdd(T ? 2 : 1);
|
||||||
|
action.accept(T);
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||||
|
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||||
|
iterable.forEach(T -> { if(filtered.add(T)) action.accept(T); });
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PeekIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||||
|
CONSUMER KEY_GENERIC_TYPE action;
|
||||||
|
|
||||||
|
public PeekIterable(ITERABLE KEY_GENERIC_TYPE iterable, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
this.iterable = iterable;
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||||
|
return ITERATORS.peek(iterable.iterator(), action);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TYPE_OBJECT
|
||||||
|
@Override
|
||||||
|
public void forEach(CONSUMER action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(this.action.andThen(action));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||||
|
Objects.requireNonNull(action);
|
||||||
|
iterable.forEach(this.action.andThen(action));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+234
-8
@@ -2,11 +2,17 @@ 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
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.function.CONSUMER;
|
||||||
|
#endif
|
||||||
|
|
||||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
import speiger.src.collections.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.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;
|
||||||
@@ -15,6 +21,10 @@ import speiger.src.collections.PACKAGE.lists.LIST;
|
|||||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||||
|
#if !TYPE_BOOLEAN
|
||||||
|
import speiger.src.collections.PACKAGE.sets.HASH_SET;
|
||||||
|
import speiger.src.collections.PACKAGE.sets.SET;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Helper class for Iterators
|
* A Helper class for Iterators
|
||||||
@@ -24,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.
|
||||||
@@ -185,6 +195,94 @@ public class ITERATORS
|
|||||||
return new FilteredIteratorBRACES(iterator, filter);
|
return new FilteredIteratorBRACES(iterator, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that filters out all duplicated elements.
|
||||||
|
* @param iterator that should be distinct
|
||||||
|
* @Type(T)
|
||||||
|
* @return a distinct iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE distinct(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||||
|
return new DistinctIteratorBRACES(iterator);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that filters out all duplicated elements from a Java Iterator.
|
||||||
|
* @param iterator that should be distinct
|
||||||
|
* @Type(T)
|
||||||
|
* @return a distinct iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE distinct(Iterator<? extends CLASS_TYPE> iterator) {
|
||||||
|
return new DistinctIteratorBRACES(wrap(iterator));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that hard limits the Iterator to a specific size
|
||||||
|
* @param iterator that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @Type(T)
|
||||||
|
* @return a limited iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE limit(ITERATOR KEY_GENERIC_TYPE iterator, long limit) {
|
||||||
|
return new LimitedIteratorBRACES(iterator, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that hard limits the Iterator to a specific size from a Java Iterator
|
||||||
|
* @param iterator that should be limited
|
||||||
|
* @param limit the amount of elements it should be limited to
|
||||||
|
* @Type(T)
|
||||||
|
* @return a limited iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE limit(Iterator<? extends CLASS_TYPE> iterator, long 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.
|
||||||
|
* @param iterator that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterator returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE peek(ITERATOR KEY_GENERIC_TYPE iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIteratorBRACES(iterator, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper function that allows to preview the result of a Iterator from a Java Iterator
|
||||||
|
* @param iterator that should be peeked at
|
||||||
|
* @param action callback that receives the value before the iterator returns it
|
||||||
|
* @Type(T)
|
||||||
|
* @return a peeked iterator
|
||||||
|
*/
|
||||||
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE peek(Iterator<? extends CLASS_TYPE> iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
return new PeekIteratorBRACES(wrap(iterator), action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to convert a Object Iterator into a Primitive Iterator
|
* Helper function to convert a Object Iterator into a Primitive Iterator
|
||||||
* @param iterator that should be converted to a unboxing iterator
|
* @param iterator that should be converted to a unboxing iterator
|
||||||
@@ -201,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,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
|
||||||
@@ -647,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
|
||||||
@@ -657,7 +755,7 @@ public class ITERATORS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int previousIndex() {
|
public int previousIndex() {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -689,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++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,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;
|
||||||
@@ -792,13 +891,93 @@ 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
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
int filtered;
|
||||||
|
#else
|
||||||
|
SET KEY_GENERIC_TYPE filtered = new HASH_SETBRACES();
|
||||||
|
#endif
|
||||||
|
KEY_TYPE lastFound;
|
||||||
|
boolean foundNext = false;
|
||||||
|
|
||||||
|
public DistinctIterator(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void compute() {
|
||||||
|
if(foundNext) return;
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
if(filtered == 3) return;
|
||||||
|
#endif
|
||||||
|
while(iterator.hasNext()) {
|
||||||
|
lastFound = iterator.NEXT();
|
||||||
|
#if TYPE_BOOLEAN
|
||||||
|
if((filtered & (lastFound ? 1 : 2)) == 0) {
|
||||||
|
filtered |= (lastFound ? 1 : 2);
|
||||||
|
foundNext = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if(filtered.add(lastFound)) {
|
||||||
|
foundNext = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
compute();
|
||||||
|
return foundNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
foundNext = false;
|
||||||
|
return lastFound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class FilteredIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
private static class FilteredIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
@@ -830,9 +1009,56 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class LimitedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
|
long limit;
|
||||||
|
|
||||||
|
public LimitedIterator(ITERATOR KEY_GENERIC_TYPE iterator, long limit) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return limit > 0 && iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
limit--;
|
||||||
|
return iterator.NEXT();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class PeekIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||||
|
{
|
||||||
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||||
|
CONSUMER KEY_GENERIC_TYPE action;
|
||||||
|
|
||||||
|
public PeekIterator(ITERATOR KEY_GENERIC_TYPE iterator, CONSUMER KEY_GENERIC_TYPE action) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE NEXT() {
|
||||||
|
if(!hasNext()) throw new NoSuchElementException();
|
||||||
|
KEY_TYPE result = iterator.NEXT();
|
||||||
|
action.accept(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.
|
||||||
@@ -200,6 +201,8 @@ public class LISTS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
@Override
|
||||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); }
|
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||||
@@ -331,6 +334,12 @@ public class LISTS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { synchronized(mutex) { return l.REMOVE(index); } }
|
public KEY_TYPE REMOVE(int index) { synchronized(mutex) { return l.REMOVE(index); } }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { synchronized(mutex) { return l.swapRemove(index); } }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) { synchronized(mutex) { return l.REMOVE_SWAP(e); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public int indexOf(Object e) { synchronized(mutex) { return l.indexOf(e); } }
|
public int indexOf(Object e) { synchronized(mutex) { return l.indexOf(e); } }
|
||||||
@@ -348,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); } }
|
||||||
@@ -380,14 +389,14 @@ public class LISTS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||||
return synchronize(l.subList(from, to));
|
return LISTS.synchronize(l.subList(from, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void size(int size) { synchronized(mutex) { l.size(size); } }
|
public void size(int size) { synchronized(mutex) { l.size(size); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public LIST KEY_GENERIC_TYPE copy() { synchronized(mutex) { return l.copy(); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess
|
private static class UnmodifiableRandomList KEY_GENERIC_TYPE extends UnmodifiableList KEY_GENERIC_TYPE implements RandomAccess
|
||||||
@@ -444,6 +453,12 @@ public class LISTS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Primitive
|
@Primitive
|
||||||
public int indexOf(Object e) { return l.indexOf(e); }
|
public int indexOf(Object e) { return l.indexOf(e); }
|
||||||
@@ -496,14 +511,14 @@ public class LISTS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||||
return unmodifiable(l.subList(from, to));
|
return LISTS.unmodifiable(l.subList(from, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void size(int size) { throw new UnsupportedOperationException(); }
|
public void size(int size) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LIST KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public LIST KEY_GENERIC_TYPE copy() { return l.copy(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
private static class EmptyList KEY_GENERIC_TYPE extends COLLECTIONS.EmptyCollection KEY_GENERIC_TYPE implements LIST KEY_GENERIC_TYPE
|
||||||
@@ -537,6 +552,12 @@ public class LISTS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
public KEY_TYPE REMOVE(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE swapRemove(int index) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean REMOVE_SWAP(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int indexOf(Object e) { return -1; }
|
public int indexOf(Object e) { return -1; }
|
||||||
|
|
||||||
@@ -581,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(); }
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -117,7 +117,7 @@ public class PRIORITY_QUEUES
|
|||||||
@Override
|
@Override
|
||||||
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
public GENERIC_SPECIAL_KEY_BRACES<E> KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } }
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return queue.copy(); } }
|
||||||
@Override
|
@Override
|
||||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -164,6 +164,6 @@ public class PRIORITY_QUEUES
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } }
|
||||||
@Override
|
@Override
|
||||||
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { synchronized(mutex) { return dequeue.copy(); } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,31 +313,64 @@ public class SETS
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { return n.copy(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return SETS.unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return unmodifiable(n.headSet(toElement, inclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { return SETS.unmodifiable(n.headSet(toElement, inclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return unmodifiable(n.tailSet(fromElement, inclusive)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { return SETS.unmodifiable(n.tailSet(fromElement, inclusive)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { return ITERATORS.unmodifiable(n.descendingIterator()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return unmodifiable(n.descendingSet()); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { return SETS.unmodifiable(n.descendingSet()); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(n.subSet(fromElement, toElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(n.subSet(fromElement, toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(n.headSet(toElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(n.headSet(toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(n.tailSet(fromElement)); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -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() { throw new UnsupportedOperationException(); }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return unmodifiable(s.subSet(fromElement, toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return unmodifiable(s.headSet(toElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return unmodifiable(s.tailSet(fromElement)); }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||||
}
|
}
|
||||||
@@ -347,8 +420,13 @@ public class SETS
|
|||||||
s = c;
|
s = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
@@ -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); } }
|
||||||
|
|
||||||
@@ -427,31 +511,31 @@ public class SETS
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return n.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, fromInclusive, toElement, toInclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.headSet(toElement, inclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement, inclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement, boolean inclusive) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement, inclusive), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
public BI_ITERATOR KEY_GENERIC_TYPE descendingIterator() { synchronized(mutex) { return n.descendingIterator(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return synchronize(n.descendingSet(), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingSet() { synchronized(mutex) { return SETS.synchronize(n.descendingSet(), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.subSet(fromElement, toElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.subSet(fromElement, toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(n.headSet(toElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(n.headSet(toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(n.tailSet(fromElement), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(n.tailSet(fromElement), mutex); } }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
private static class SynchronizedSortedTrimSet KEY_GENERIC_TYPE extends SynchronizedSortedSet KEY_GENERIC_TYPE implements ITrimmable
|
||||||
@@ -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() { throw new UnsupportedOperationException(); }
|
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.subSet(fromElement, toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return synchronize(s.headSet(toElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return synchronize(s.tailSet(fromElement), mutex); } }
|
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||||
|
@Override
|
||||||
|
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(); } }
|
||||||
}
|
}
|
||||||
@@ -558,26 +679,25 @@ public class SETS
|
|||||||
|
|
||||||
private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
private static class SynchronizedSet KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
|
||||||
{
|
{
|
||||||
#if !TYPE_OBJECT
|
|
||||||
SET KEY_GENERIC_TYPE s;
|
SET KEY_GENERIC_TYPE s;
|
||||||
#endif
|
|
||||||
|
|
||||||
SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
SynchronizedSet(SET KEY_GENERIC_TYPE c) {
|
||||||
super(c);
|
super(c);
|
||||||
#if !TYPE_OBJECT
|
|
||||||
s = c;
|
s = c;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
SynchronizedSet(SET KEY_GENERIC_TYPE c, Object mutex) {
|
||||||
super(c, mutex);
|
super(c, mutex);
|
||||||
#if !TYPE_OBJECT
|
|
||||||
s = c;
|
s = c;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
public KEY_TYPE addOrGet(KEY_TYPE o) { synchronized(mutex) { return s.addOrGet(o); } }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+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; }
|
||||||
}
|
}
|
||||||
|
|||||||
+317
-87
@@ -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,31 +439,33 @@ public class MAPS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return 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 unmodifiable(map.firstEntry()); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return unmodifiable(map.lastEntry()); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return MAPS.unmodifiable(map.lastEntry()); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { return MAPS.unmodifiable(map.subMap(fromKey, fromInclusive, toKey, toInclusive)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return unmodifiable(map.headMap(toKey, inclusive)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { return MAPS.unmodifiable(map.headMap(toKey, inclusive)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return unmodifiable(map.tailMap(fromKey, inclusive)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { return MAPS.unmodifiable(map.tailMap(fromKey, inclusive)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||||
@@ -412,26 +485,26 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public KEY_TYPE ceilingKey(KEY_TYPE key) { return map.ceilingKey(key); }
|
public KEY_TYPE ceilingKey(KEY_TYPE key) { return map.ceilingKey(key); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return unmodifiable(map.lowerEntry(key)); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE lowerEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.lowerEntry(key)); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return unmodifiable(map.higherEntry(key)); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE higherEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.higherEntry(key)); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return unmodifiable(map.floorEntry(key)); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE floorEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.floorEntry(key)); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return 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;
|
||||||
}
|
}
|
||||||
@@ -449,27 +522,69 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||||
@Override
|
@Override
|
||||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return unmodifiable(map.subMap(fromKey, toKey)); }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return unmodifiable(map.headMap(toKey)); }
|
|
||||||
@Override
|
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return unmodifiable(map.tailMap(fromKey)); }
|
|
||||||
@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 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
|
||||||
|
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
||||||
|
@Override
|
||||||
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
|
||||||
|
@Override
|
||||||
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { return MAPS.unmodifiable(map.headMap(toKey)); }
|
||||||
|
@Override
|
||||||
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||||
|
@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(); }
|
||||||
|
@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 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)
|
||||||
@@ -548,7 +725,7 @@ public class MAPS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||||
s.forEach(T -> action.accept(unmodifiable(T)));
|
s.forEach(T -> action.accept(MAPS.unmodifiable(T)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -558,7 +735,7 @@ public class MAPS
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasNext() { return iter.hasNext(); }
|
public boolean hasNext() { return iter.hasNext(); }
|
||||||
@Override
|
@Override
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return unmodifiable(iter.next()); }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { return MAPS.unmodifiable(iter.next()); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,31 +760,33 @@ public class MAPS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return synchronize(map.descendingMap(), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { synchronized(mutex) { return MAPS.synchronize(map.descendingMap(), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { synchronized(mutex) { return SETS.synchronize(map.navigableKeySet(), mutex); } }
|
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { synchronized(mutex) { return SETS.synchronize(map.navigableKeySet(), mutex); } }
|
||||||
@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
|
||||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE lowerKey(KEY_TYPE key) { synchronized(mutex) { return map.lowerKey(key); } }
|
public KEY_TYPE lowerKey(KEY_TYPE key) { synchronized(mutex) { return map.lowerKey(key); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -625,26 +804,26 @@ 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 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); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.headMap(toKey, inclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey, inclusive), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey, boolean inclusive) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey, inclusive), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { map.setDefaultMaxValue(e); } }
|
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { map.setDefaultMaxValue(e); } }
|
||||||
@Override
|
@Override
|
||||||
@@ -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,26 +934,16 @@ 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
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return 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
|
||||||
|
public SORTED_SET KEY_GENERIC_TYPE keySet() { synchronized(mutex) { return SETS.synchronize(map.keySet(), mutex); } }
|
||||||
@Override
|
@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
|
||||||
@@ -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
|
||||||
@@ -741,13 +967,13 @@ public class MAPS
|
|||||||
public CLASS_TYPE lastKey() { synchronized(mutex) { return map.lastKey(); } }
|
public CLASS_TYPE lastKey() { synchronized(mutex) { return map.lastKey(); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.subMap(fromKey, toKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return synchronize(map.headMap(toKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { synchronized(mutex) { return MAPS.synchronize(map.headMap(toKey), mutex); } }
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return synchronize(map.tailMap(fromKey), mutex); } }
|
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ public class HashUtil
|
|||||||
{
|
{
|
||||||
/** Minimum HashMap Capacity */
|
/** Minimum HashMap Capacity */
|
||||||
public static final int DEFAULT_MIN_CAPACITY = 16;
|
public static final int DEFAULT_MIN_CAPACITY = 16;
|
||||||
|
/** Minimum ConcurrentHashMap Concurrency */
|
||||||
|
public static final int DEFAULT_MIN_CONCURRENCY = 4;
|
||||||
/** Default HashMap Load Factor */
|
/** Default HashMap Load Factor */
|
||||||
public static final float DEFAULT_LOAD_FACTOR = 0.75F;
|
public static final float DEFAULT_LOAD_FACTOR = 0.75F;
|
||||||
/** HashMap Load Factor with reduced hash collisions but more memory usage */
|
/** HashMap Load Factor with reduced hash collisions but more memory usage */
|
||||||
@@ -79,6 +81,26 @@ public class HashUtil
|
|||||||
return x + 1L;
|
return x + 1L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function that finds out how many bits are required to store the number Provided
|
||||||
|
* @param value to get the required bits to store.
|
||||||
|
* @return the required bits to store that number
|
||||||
|
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
|
||||||
|
*/
|
||||||
|
public static int getRequiredBits(int value) {
|
||||||
|
return Integer.bitCount(nextPowerOfTwo(value+1)-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function that finds out how many bits are required to store the number Provided
|
||||||
|
* @param value to get the required bits to store.
|
||||||
|
* @return the required bits to store that number
|
||||||
|
* @note Really useful for compression. Reducing data that is inserted into a GZIP algorithm.
|
||||||
|
*/
|
||||||
|
public static int getRequiredBits(long value) {
|
||||||
|
return Long.bitCount(nextPowerOfTwo(value+1L)-1L);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that creates the ideal array size for HashMap
|
* Helper function that creates the ideal array size for HashMap
|
||||||
* @param size the original array size
|
* @param size the original array size
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ public class SanityChecks
|
|||||||
* @throws IllegalStateException if offset or accessSize is negative or the range goes out of the array-size
|
* @throws IllegalStateException if offset or accessSize is negative or the range goes out of the array-size
|
||||||
*/
|
*/
|
||||||
public static void checkArrayCapacity(int arraySize, int offset, int accessSize) {
|
public static void checkArrayCapacity(int arraySize, int offset, int accessSize) {
|
||||||
if(offset < 0) throw new IllegalStateException("Offset is negative ("+offset+")");
|
if(offset < 0) throw new IndexOutOfBoundsException("Offset is negative ("+offset+")");
|
||||||
else if(accessSize < 0) throw new IllegalStateException("Size is negative ("+accessSize+")");
|
else if(accessSize < 0) throw new IllegalArgumentException("Size is negative ("+accessSize+")");
|
||||||
else if(arraySize < offset + accessSize) throw new IndexOutOfBoundsException("Index (" + (offset + accessSize) + ") is not in size (" + arraySize + ")");
|
else if(arraySize < offset + accessSize) throw new IndexOutOfBoundsException("Index (" + (offset + accessSize) + ") is not in size (" + arraySize + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +104,14 @@ public class SanityChecks
|
|||||||
getPool().execute(task);
|
getPool().execute(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Helper method to start a Async Task. This method will not await the finalization of said task
|
||||||
|
* @param task the Task to invoke
|
||||||
|
*/
|
||||||
|
public static void invokeAsyncTask(Runnable task) {
|
||||||
|
getPool().execute(task);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to control what ForkJoinPool is being used for any given task.
|
* Helper method to control what ForkJoinPool is being used for any given task.
|
||||||
* @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled.
|
* @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled.
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package speiger.src.collections.ints.base;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
|
||||||
|
import speiger.src.collections.tests.OrderedMapTests;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class BaseInt2IntOrderedMapTest extends BaseInt2IntMapTest
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public abstract Int2IntOrderedMap createMap(int[] keys, int[] values);
|
||||||
|
@Override
|
||||||
|
public abstract Int2IntOrderedMap createEmptyMap();
|
||||||
|
|
||||||
|
public EnumSet<OrderedMapTests> getValidOrderedMapTests() { return EnumSet.allOf(OrderedMapTests.class); }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutMove()
|
||||||
|
{
|
||||||
|
if(!getValidOrderedMapTests().contains(OrderedMapTests.PUT_MOVE)) return;
|
||||||
|
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
|
||||||
|
Assert.assertEquals(120, map.firstIntKey());
|
||||||
|
Assert.assertEquals(-1, map.firstIntValue());
|
||||||
|
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
|
||||||
|
Assert.assertEquals(121, map.lastIntKey());
|
||||||
|
Assert.assertEquals(-2, map.lastIntValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMove()
|
||||||
|
{
|
||||||
|
if(!getValidOrderedMapTests().contains(OrderedMapTests.MOVE)) return;
|
||||||
|
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Assert.assertTrue(map.moveToFirst(99));
|
||||||
|
Assert.assertFalse(map.moveToFirst(99));
|
||||||
|
Assert.assertEquals(99, map.firstIntKey());
|
||||||
|
Assert.assertTrue(map.moveToLast(0));
|
||||||
|
Assert.assertFalse(map.moveToLast(0));
|
||||||
|
Assert.assertEquals(0, map.lastIntKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetMove()
|
||||||
|
{
|
||||||
|
if(!getValidOrderedMapTests().contains(OrderedMapTests.GET_MOVE)) return;
|
||||||
|
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Assert.assertNotEquals(99, map.firstIntValue());
|
||||||
|
Assert.assertEquals(99, map.getAndMoveToFirst(99));
|
||||||
|
Assert.assertEquals(99, map.firstIntValue());
|
||||||
|
Assert.assertNotEquals(0, map.lastIntValue());
|
||||||
|
Assert.assertEquals(0, map.getAndMoveToLast(0));
|
||||||
|
Assert.assertEquals(0, map.lastIntValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFirst()
|
||||||
|
{
|
||||||
|
if(!getValidOrderedMapTests().contains(OrderedMapTests.FIRST)) return;
|
||||||
|
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Assert.assertEquals(map.pollFirstIntKey(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLast()
|
||||||
|
{
|
||||||
|
if(!getValidOrderedMapTests().contains(OrderedMapTests.LAST)) return;
|
||||||
|
Int2IntOrderedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
||||||
|
Assert.assertEquals(map.pollLastIntKey(), 99);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,45 +18,6 @@ public abstract class BaseInt2IntSortedMapTest extends BaseInt2IntMapTest
|
|||||||
|
|
||||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.allOf(SortedMapTests.class); }
|
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.allOf(SortedMapTests.class); }
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPutMove()
|
|
||||||
{
|
|
||||||
if(!getValidSortedMapTests().contains(SortedMapTests.PUT_MOVE)) return;
|
|
||||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
|
||||||
Assert.assertEquals(0, map.putAndMoveToFirst(120, -1));
|
|
||||||
Assert.assertEquals(120, map.firstIntKey());
|
|
||||||
Assert.assertEquals(-1, map.firstIntValue());
|
|
||||||
Assert.assertEquals(0, map.putAndMoveToLast(121, -2));
|
|
||||||
Assert.assertEquals(121, map.lastIntKey());
|
|
||||||
Assert.assertEquals(-2, map.lastIntValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMove()
|
|
||||||
{
|
|
||||||
if(!getValidSortedMapTests().contains(SortedMapTests.MOVE)) return;
|
|
||||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
|
||||||
Assert.assertTrue(map.moveToFirst(99));
|
|
||||||
Assert.assertFalse(map.moveToFirst(99));
|
|
||||||
Assert.assertEquals(99, map.firstIntKey());
|
|
||||||
Assert.assertTrue(map.moveToLast(0));
|
|
||||||
Assert.assertFalse(map.moveToLast(0));
|
|
||||||
Assert.assertEquals(0, map.lastIntKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetMove()
|
|
||||||
{
|
|
||||||
if(!getValidSortedMapTests().contains(SortedMapTests.GET_MOVE)) return;
|
|
||||||
Int2IntSortedMap map = createMap(TEST_ARRAY, TEST_ARRAY);
|
|
||||||
Assert.assertNotEquals(99, map.firstIntValue());
|
|
||||||
Assert.assertEquals(99, map.getAndMoveToFirst(99));
|
|
||||||
Assert.assertEquals(99, map.firstIntValue());
|
|
||||||
Assert.assertNotEquals(0, map.lastIntValue());
|
|
||||||
Assert.assertEquals(0, map.getAndMoveToLast(0));
|
|
||||||
Assert.assertEquals(0, map.lastIntValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirst()
|
public void testFirst()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,6 +118,14 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
|||||||
Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
|
Assert.assertTrue(collection.removeAll(Arrays.asList(IntArrays.wrap(CONTAINS_ARRAY))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveAllListener() {
|
||||||
|
if(!getValidCollectionTests().contains(CollectionTest.REMOVE_ALL_LISTENER)) return;
|
||||||
|
IntCollection collection = create(TEST_ARRAY);
|
||||||
|
Assert.assertTrue(collection.removeAll(create(CONTAINS_ARRAY), T -> {}));
|
||||||
|
Assert.assertFalse(collection.removeAll(create(CONTAINS_ARRAY), T -> Assert.assertTrue(false)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetainAll() {
|
public void testRetainAll() {
|
||||||
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return;
|
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL)) return;
|
||||||
@@ -135,6 +143,23 @@ public abstract class BaseIntCollectionTest extends BaseIntIterableTest
|
|||||||
Assert.assertTrue(collection.isEmpty());
|
Assert.assertTrue(collection.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRetainAllListener() {
|
||||||
|
if(!getValidCollectionTests().contains(CollectionTest.RETAIN_ALL_LISTENER)) return;
|
||||||
|
IntCollection collection = create(TEST_ARRAY);
|
||||||
|
IntCollection retained = create(CONTAINS_ARRAY);
|
||||||
|
Assert.assertTrue(collection.retainAll(retained, T -> {}));
|
||||||
|
Assert.assertFalse(collection.retainAll(retained, T -> Assert.assertTrue(false)));
|
||||||
|
Assert.assertEquals(CONTAINS_ARRAY.length, collection.size());
|
||||||
|
int[] retainedArray = retained.toIntArray();
|
||||||
|
int[] collectionArray = collection.toIntArray();
|
||||||
|
IntArrays.stableSort(retainedArray);
|
||||||
|
IntArrays.stableSort(collectionArray);
|
||||||
|
Assert.assertArrayEquals(retainedArray, collectionArray);
|
||||||
|
collection.retainAll(IntCollections.EMPTY, T -> {});
|
||||||
|
Assert.assertTrue(collection.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToArray() {
|
public void testToArray() {
|
||||||
if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return;
|
if(!getValidCollectionTests().contains(CollectionTest.TO_ARRAY)) return;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package speiger.src.collections.ints.base;
|
package speiger.src.collections.ints.base;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@@ -8,6 +9,11 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import speiger.src.collections.ints.collections.IntIterable;
|
import speiger.src.collections.ints.collections.IntIterable;
|
||||||
import speiger.src.collections.ints.collections.IntIterator;
|
import speiger.src.collections.ints.collections.IntIterator;
|
||||||
|
import speiger.src.collections.ints.lists.IntArrayList;
|
||||||
|
import speiger.src.collections.ints.utils.IntArrays;
|
||||||
|
import speiger.src.collections.ints.utils.IntIterators;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||||
import speiger.src.collections.tests.IterableTest;
|
import speiger.src.collections.tests.IterableTest;
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
@@ -15,6 +21,7 @@ public abstract class BaseIntIterableTest
|
|||||||
{
|
{
|
||||||
protected static final int[] EMPTY_ARRAY = new int[0];
|
protected static final int[] EMPTY_ARRAY = new int[0];
|
||||||
protected static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
protected static final int[] TEST_ARRAY = IntStream.range(0, 100).toArray();
|
||||||
|
protected static final int[] DISTINCT_ARRAY = IntStream.range(0, 100).flatMap(T -> Arrays.stream(new int[]{T, T})).toArray();
|
||||||
|
|
||||||
protected abstract IntIterable create(int[] data);
|
protected abstract IntIterable create(int[] data);
|
||||||
|
|
||||||
@@ -65,4 +72,103 @@ public abstract class BaseIntIterableTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamCount() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_COUNT)) {
|
||||||
|
long expected = IntStream.of(TEST_ARRAY).filter(T -> T % 2 == 0).count();
|
||||||
|
int size = create(TEST_ARRAY).count(T -> T % 2 == 0);
|
||||||
|
Assert.assertEquals(expected, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamFilter() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_FILTER)) {
|
||||||
|
int[] expected = IntStream.of(TEST_ARRAY).filter(T -> T % 2 == 0).toArray();
|
||||||
|
int[] actual = IntIterators.pour(create(TEST_ARRAY).filter(T -> T % 2 == 0).iterator()).toIntArray();
|
||||||
|
IntArrays.stableSort(actual);
|
||||||
|
Assert.assertArrayEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamFindFirst() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_FIND_FIRST)) {
|
||||||
|
int expected = IntStream.of(TEST_ARRAY).filter(T -> T / 50 > 0).findFirst().getAsInt();
|
||||||
|
int actual = create(TEST_ARRAY).findFirst(T -> T / 50 > 0);
|
||||||
|
Assert.assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void teastStreamDistinct() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_DISTINCT)) {
|
||||||
|
int[] expected = IntStream.of(DISTINCT_ARRAY).distinct().toArray();
|
||||||
|
int[] actual = IntIterators.pour(create(DISTINCT_ARRAY).distinct().iterator()).toIntArray();
|
||||||
|
IntArrays.stableSort(actual);
|
||||||
|
Assert.assertArrayEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamLimit() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_LIMIT)) {
|
||||||
|
int[] expected = IntStream.of(TEST_ARRAY).limit(25).toArray();
|
||||||
|
int[] actual = IntIterators.pour(create(TEST_ARRAY).limit(25).iterator()).toIntArray();
|
||||||
|
Assert.assertEquals(expected.length, actual.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamMap() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_MAP)) {
|
||||||
|
Integer[] expected = IntStream.of(TEST_ARRAY).mapToObj(Integer::valueOf).toArray(Integer[]::new);
|
||||||
|
Integer[] actual = ObjectIterators.pour(create(TEST_ARRAY).map(Integer::valueOf).iterator()).toArray(Integer[]::new);
|
||||||
|
ObjectArrays.stableSort(actual);
|
||||||
|
Assert.assertArrayEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamMatches() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_MATCHES)) {
|
||||||
|
IntIterable iterable = create(TEST_ARRAY);
|
||||||
|
Assert.assertTrue(iterable.matchesAll(T -> T >= 0));
|
||||||
|
Assert.assertFalse(iterable.matchesAll(T -> T < 0));
|
||||||
|
Assert.assertTrue(iterable.matchesAny(T -> T % 2 != 0));
|
||||||
|
Assert.assertFalse(iterable.matchesAny(T -> T % 2 >= 2));
|
||||||
|
Assert.assertTrue(iterable.matchesNone(T -> T % 2 >= 2));
|
||||||
|
Assert.assertFalse(iterable.matchesNone(T -> T % 2 != 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamPeek() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_PEEK)) {
|
||||||
|
int[] peekCount = new int[2];
|
||||||
|
create(TEST_ARRAY).peek(T -> peekCount[0]++).forEach(T -> peekCount[1]++);
|
||||||
|
Assert.assertEquals(TEST_ARRAY.length, peekCount[0]);
|
||||||
|
Assert.assertEquals(TEST_ARRAY.length, peekCount[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamPour() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_POUR)) {
|
||||||
|
int[] expected = TEST_ARRAY;
|
||||||
|
int[] actual = create(TEST_ARRAY).pour(new IntArrayList()).toIntArray();
|
||||||
|
IntArrays.stableSort(actual);
|
||||||
|
Assert.assertArrayEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamReduce() {
|
||||||
|
if(getValidIterableTests().contains(IterableTest.STREAM_REDUCE)) {
|
||||||
|
int expected = IntStream.of(TEST_ARRAY).reduce(0, Integer::sum);
|
||||||
|
int actual = create(TEST_ARRAY).reduce(0, Integer::sum);
|
||||||
|
Assert.assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,16 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
|
|||||||
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
|
for(int i = 0;i<ADD_ARRAY.length;i++) Assert.assertEquals(ADD_ARRAY[i], list.getInt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpecialAdd() {
|
||||||
|
if(getValidListTests().contains(ListTest.ADD_SPECIAL)) return;
|
||||||
|
IntList list = create(TEST_ARRAY);
|
||||||
|
Assert.assertFalse(list.addIfAbsent(50));
|
||||||
|
Assert.assertTrue(list.addIfPresent(50));
|
||||||
|
Assert.assertTrue(list.addIfAbsent(150));
|
||||||
|
Assert.assertFalse(list.addIfAbsent(150));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testIndex() {
|
public void testIndex() {
|
||||||
@@ -173,6 +183,17 @@ public abstract class BaseIntListTest extends BaseIntCollectionTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSwapRemove() {
|
||||||
|
if(getValidListTests().contains(ListTest.REMOVE_SWAP)) return;
|
||||||
|
IntList list = create(TEST_ARRAY);
|
||||||
|
Assert.assertEquals(TEST_ARRAY[50], list.swapRemove(50));
|
||||||
|
Assert.assertEquals(TEST_ARRAY[TEST_ARRAY.length-1], list.getInt(50));
|
||||||
|
list = create(TEST_ARRAY);
|
||||||
|
Assert.assertTrue(list.swapRemoveInt(50));
|
||||||
|
Assert.assertFalse(list.swapRemoveInt(50));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListIterator() {
|
public void testListIterator() {
|
||||||
if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return;
|
if(getValidListTests().contains(ListTest.LIST_ITERATOR)) return;
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package speiger.src.collections.ints.base;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.sets.IntOrderedSet;
|
||||||
|
import speiger.src.collections.tests.OrderedSetTest;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class BaseIntOrderedSetTest extends BaseIntCollectionTest
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected abstract IntOrderedSet create(int[] data);
|
||||||
|
|
||||||
|
protected EnumSet<OrderedSetTest> getValidOrderedSetTests() { return EnumSet.allOf(OrderedSetTest.class); }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMoveTest() {
|
||||||
|
if(getValidOrderedSetTests().contains(OrderedSetTest.ADD_MOVE)) {
|
||||||
|
IntOrderedSet set = create(TEST_ARRAY);
|
||||||
|
Assert.assertTrue(set.addAndMoveToFirst(1050));
|
||||||
|
Assert.assertFalse(set.addAndMoveToLast(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void moveTest() {
|
||||||
|
if(getValidOrderedSetTests().contains(OrderedSetTest.MOVE)) {
|
||||||
|
IntOrderedSet set = create(TEST_ARRAY);
|
||||||
|
Assert.assertTrue(set.moveToFirst(5));
|
||||||
|
Assert.assertFalse(set.moveToFirst(5));
|
||||||
|
Assert.assertTrue(set.moveToLast(5));
|
||||||
|
Assert.assertFalse(set.moveToLast(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void peekTest() {
|
||||||
|
if(getValidOrderedSetTests().contains(OrderedSetTest.PEEK)) {
|
||||||
|
IntOrderedSet set = create(TEST_ARRAY);
|
||||||
|
Assert.assertEquals(set.firstInt(), 0);
|
||||||
|
Assert.assertEquals(set.lastInt(), 99);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pollTest() {
|
||||||
|
if(getValidOrderedSetTests().contains(OrderedSetTest.POLL)) {
|
||||||
|
IntOrderedSet set = create(TEST_ARRAY);
|
||||||
|
for(int i = 0;i<100;i++)
|
||||||
|
{
|
||||||
|
Assert.assertEquals(i, set.pollFirstInt());
|
||||||
|
}
|
||||||
|
set = create(TEST_ARRAY);
|
||||||
|
for(int i = 99;i>=0;i--)
|
||||||
|
{
|
||||||
|
Assert.assertEquals(i, set.pollLastInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,24 @@ public abstract class BaseIntPriorityQueueTest extends BaseIntIterableTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnorderedPeek() {
|
||||||
|
EnumSet<PriorityQueueTest> valid = getValidPriorityQueueTests();
|
||||||
|
if(valid.contains(PriorityQueueTest.IN_OUT) && valid.contains(PriorityQueueTest.PEEK) && !isUnsortedRead()) {
|
||||||
|
IntPriorityQueue queue = create(EMPTY_ARRAY);
|
||||||
|
for(int i = 0;i<100;i++) {
|
||||||
|
queue.enqueue(i);
|
||||||
|
}
|
||||||
|
for(int i = 0;i<25;i++) {
|
||||||
|
queue.dequeue();
|
||||||
|
queue.enqueue(i);
|
||||||
|
}
|
||||||
|
for(int i = 0;i<100;i++) {
|
||||||
|
Assert.assertEquals((i+25) % 100, queue.peek(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testToArray() {
|
public void testToArray() {
|
||||||
|
|||||||
@@ -16,26 +16,6 @@ public abstract class BaseIntSortedSetTest extends BaseIntCollectionTest
|
|||||||
|
|
||||||
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.allOf(SortedSetTest.class); }
|
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.allOf(SortedSetTest.class); }
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addMoveTest() {
|
|
||||||
if(getValidSortedSetTests().contains(SortedSetTest.ADD_MOVE)) {
|
|
||||||
IntSortedSet set = create(TEST_ARRAY);
|
|
||||||
Assert.assertTrue(set.addAndMoveToFirst(1050));
|
|
||||||
Assert.assertFalse(set.addAndMoveToLast(5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void moveTest() {
|
|
||||||
if(getValidSortedSetTests().contains(SortedSetTest.MOVE)) {
|
|
||||||
IntSortedSet set = create(TEST_ARRAY);
|
|
||||||
Assert.assertTrue(set.moveToFirst(5));
|
|
||||||
Assert.assertFalse(set.moveToFirst(5));
|
|
||||||
Assert.assertTrue(set.moveToLast(5));
|
|
||||||
Assert.assertFalse(set.moveToLast(5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void peekTest() {
|
public void peekTest() {
|
||||||
if(getValidSortedSetTests().contains(SortedSetTest.PEEK)) {
|
if(getValidSortedSetTests().contains(SortedSetTest.PEEK)) {
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
package speiger.src.collections.ints.maps;
|
package speiger.src.collections.ints.maps;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
||||||
import speiger.src.collections.ints.maps.impl.tree.Int2IntAVLTreeMap;
|
import speiger.src.collections.ints.maps.impl.tree.Int2IntAVLTreeMap;
|
||||||
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||||
import speiger.src.collections.tests.SortedMapTests;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class Int2IntAVLTreeMapTest extends BaseInt2IntNavigableMapTest
|
public class Int2IntAVLTreeMapTest extends BaseInt2IntNavigableMapTest
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
package speiger.src.collections.ints.maps;
|
package speiger.src.collections.ints.maps;
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
|
||||||
import speiger.src.collections.ints.maps.impl.misc.Int2IntArrayMap;
|
import speiger.src.collections.ints.maps.impl.misc.Int2IntArrayMap;
|
||||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class Int2IntArrayMapTest extends BaseInt2IntSortedMapTest
|
public class Int2IntArrayMapTest extends BaseInt2IntOrderedMapTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
public Int2IntOrderedMap createMap(int[] keys, int[] values)
|
||||||
{
|
{
|
||||||
return new Int2IntArrayMap(keys, values);
|
return new Int2IntArrayMap(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2IntSortedMap createEmptyMap()
|
public Int2IntOrderedMap createEmptyMap()
|
||||||
{
|
{
|
||||||
return new Int2IntArrayMap();
|
return new Int2IntArrayMap();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-11
@@ -1,26 +1,20 @@
|
|||||||
package speiger.src.collections.ints.maps;
|
package speiger.src.collections.ints.maps;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
|
||||||
import speiger.src.collections.ints.maps.impl.customHash.Int2IntLinkedOpenCustomHashMap;
|
import speiger.src.collections.ints.maps.impl.customHash.Int2IntLinkedOpenCustomHashMap;
|
||||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
|
||||||
import speiger.src.collections.tests.SortedMapTests;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class Int2IntLinkedOpenCustomHashMapTest extends BaseInt2IntSortedMapTest
|
public class Int2IntLinkedOpenCustomHashMapTest extends BaseInt2IntOrderedMapTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
|
public Int2IntOrderedMap createMap(int[] keys, int[] values)
|
||||||
|
|
||||||
@Override
|
|
||||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
|
||||||
{
|
{
|
||||||
return new Int2IntLinkedOpenCustomHashMap(keys, values, STRATEGY);
|
return new Int2IntLinkedOpenCustomHashMap(keys, values, STRATEGY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2IntSortedMap createEmptyMap()
|
public Int2IntOrderedMap createEmptyMap()
|
||||||
{
|
{
|
||||||
return new Int2IntLinkedOpenCustomHashMap(STRATEGY);
|
return new Int2IntLinkedOpenCustomHashMap(STRATEGY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,20 @@
|
|||||||
package speiger.src.collections.ints.maps;
|
package speiger.src.collections.ints.maps;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import speiger.src.collections.ints.base.BaseInt2IntOrderedMapTest;
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseInt2IntSortedMapTest;
|
|
||||||
import speiger.src.collections.ints.maps.impl.hash.Int2IntLinkedOpenHashMap;
|
import speiger.src.collections.ints.maps.impl.hash.Int2IntLinkedOpenHashMap;
|
||||||
import speiger.src.collections.ints.maps.interfaces.Int2IntSortedMap;
|
import speiger.src.collections.ints.maps.interfaces.Int2IntOrderedMap;
|
||||||
import speiger.src.collections.tests.SortedMapTests;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class Int2IntLinkedOpenHashMapTest extends BaseInt2IntSortedMapTest
|
public class Int2IntLinkedOpenHashMapTest extends BaseInt2IntOrderedMapTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.SUB_MAP, SortedMapTests.TAIL_MAP, SortedMapTests.HEAD_MAP)); }
|
public Int2IntOrderedMap createMap(int[] keys, int[] values)
|
||||||
|
|
||||||
@Override
|
|
||||||
public Int2IntSortedMap createMap(int[] keys, int[] values)
|
|
||||||
{
|
{
|
||||||
return new Int2IntLinkedOpenHashMap(keys, values);
|
return new Int2IntLinkedOpenHashMap(keys, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2IntSortedMap createEmptyMap()
|
public Int2IntOrderedMap createEmptyMap()
|
||||||
{
|
{
|
||||||
return new Int2IntLinkedOpenHashMap();
|
return new Int2IntLinkedOpenHashMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
package speiger.src.collections.ints.maps;
|
package speiger.src.collections.ints.maps;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
import speiger.src.collections.ints.base.BaseInt2IntNavigableMapTest;
|
||||||
import speiger.src.collections.ints.maps.impl.tree.Int2IntRBTreeMap;
|
import speiger.src.collections.ints.maps.impl.tree.Int2IntRBTreeMap;
|
||||||
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
import speiger.src.collections.ints.maps.interfaces.Int2IntNavigableMap;
|
||||||
import speiger.src.collections.tests.SortedMapTests;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class Int2IntRBTreeMapTest extends BaseInt2IntNavigableMapTest
|
public class Int2IntRBTreeMapTest extends BaseInt2IntNavigableMapTest
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public EnumSet<SortedMapTests> getValidSortedMapTests() { return EnumSet.complementOf(EnumSet.of(SortedMapTests.GET_MOVE, SortedMapTests.MOVE, SortedMapTests.PUT_MOVE)); }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
public Int2IntNavigableMap createMap(int[] keys, int[] values)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package speiger.src.collections.ints.sets;
|
package speiger.src.collections.ints.sets;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
|
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
|
||||||
import speiger.src.collections.tests.SortedSetTest;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class IntAVLTreeSetTests extends BaseIntNavigableSetTest
|
public class IntAVLTreeSetTests extends BaseIntNavigableSetTest
|
||||||
@@ -12,7 +9,4 @@ public class IntAVLTreeSetTests extends BaseIntNavigableSetTest
|
|||||||
protected IntNavigableSet create(int[] data) {
|
protected IntNavigableSet create(int[] data) {
|
||||||
return new IntAVLTreeSet(data);
|
return new IntAVLTreeSet(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package speiger.src.collections.ints.sets;
|
package speiger.src.collections.ints.sets;
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
|
import speiger.src.collections.ints.base.BaseIntOrderedSetTest;
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class IntArraySetTests extends BaseIntSortedSetTest
|
public class IntArraySetTests extends BaseIntOrderedSetTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected IntSortedSet create(int[] data) { return new IntArraySet(data.clone()); }
|
protected IntOrderedSet create(int[] data) { return new IntArraySet(data.clone()); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,21 +3,14 @@ package speiger.src.collections.ints.sets;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseIntCollectionTest;
|
import speiger.src.collections.ints.base.BaseIntCollectionTest;
|
||||||
import speiger.src.collections.ints.base.BaseIntSortedSetTest;
|
import speiger.src.collections.ints.base.BaseIntOrderedSetTest;
|
||||||
import speiger.src.collections.ints.collections.IntCollection;
|
import speiger.src.collections.ints.collections.IntCollection;
|
||||||
import speiger.src.collections.ints.utils.IntStrategy;
|
import speiger.src.collections.ints.utils.IntStrategy;
|
||||||
import speiger.src.collections.tests.CollectionTest;
|
import speiger.src.collections.tests.CollectionTest;
|
||||||
import speiger.src.collections.tests.SortedSetTest;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class IntHashSetTests
|
public class IntHashSetTests
|
||||||
{
|
{
|
||||||
public static abstract class BaseIntOpenHashSetTests extends BaseIntSortedSetTest
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.ADD_MOVE, SortedSetTest.MOVE, SortedSetTest.PEEK, SortedSetTest.POLL); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class IntOpenHashSetTests extends BaseIntCollectionTest
|
public static class IntOpenHashSetTests extends BaseIntCollectionTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -32,10 +25,10 @@ public class IntHashSetTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IntLinkedOpenHashSetTests extends BaseIntOpenHashSetTests
|
public static class IntLinkedOpenHashSetTests extends BaseIntOrderedSetTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected IntSortedSet create(int[] data) { return new IntLinkedOpenHashSet(data); }
|
protected IntOrderedSet create(int[] data) { return new IntLinkedOpenHashSet(data); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IntOpenCustomHashSetTests extends BaseIntCollectionTest
|
public static class IntOpenCustomHashSetTests extends BaseIntCollectionTest
|
||||||
@@ -52,10 +45,10 @@ public class IntHashSetTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IntLinkedOpenCustomHashSetTests extends BaseIntOpenHashSetTests
|
public static class IntLinkedOpenCustomHashSetTests extends BaseIntOrderedSetTest
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected IntSortedSet create(int[] data) { return new IntLinkedOpenCustomHashSet(data, new DefaultStrategy()); }
|
protected IntOrderedSet create(int[] data) { return new IntLinkedOpenCustomHashSet(data, new DefaultStrategy()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DefaultStrategy implements IntStrategy
|
public static class DefaultStrategy implements IntStrategy
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package speiger.src.collections.ints.sets;
|
package speiger.src.collections.ints.sets;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
|
import speiger.src.collections.ints.base.BaseIntNavigableSetTest;
|
||||||
import speiger.src.collections.tests.SortedSetTest;
|
|
||||||
|
|
||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public class IntRBTreeSetTests extends BaseIntNavigableSetTest
|
public class IntRBTreeSetTests extends BaseIntNavigableSetTest
|
||||||
@@ -13,7 +10,4 @@ public class IntRBTreeSetTests extends BaseIntNavigableSetTest
|
|||||||
protected IntNavigableSet create(int[] data) {
|
protected IntNavigableSet create(int[] data) {
|
||||||
return new IntRBTreeSet(data);
|
return new IntRBTreeSet(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EnumSet<SortedSetTest> getValidSortedSetTests() { return EnumSet.of(SortedSetTest.PEEK, SortedSetTest.POLL, SortedSetTest.HEAD_SET, SortedSetTest.SUB_SET, SortedSetTest.TAIL_SET);}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package speiger.src.collections.objects.list;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.ListTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.TestStringListGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
import com.google.common.collect.testing.features.ListFeature;
|
||||||
|
import com.google.common.collect.testing.testers.ListListIteratorTester;
|
||||||
|
import com.google.common.collect.testing.testers.ListSubListTester;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.ints.lists.CopyOnWriteIntArrayList;
|
||||||
|
import speiger.src.collections.ints.lists.ImmutableIntList;
|
||||||
|
import speiger.src.collections.ints.lists.IntArrayList;
|
||||||
|
import speiger.src.collections.ints.lists.IntLinkedList;
|
||||||
|
import speiger.src.collections.ints.lists.IntList;
|
||||||
|
import speiger.src.collections.objects.lists.CopyOnWriteObjectArrayList;
|
||||||
|
import speiger.src.collections.objects.lists.ImmutableObjectList;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectLinkedList;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ObjectListTests extends TestCase
|
||||||
|
{
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
TestSuite suite = new TestSuite("Lists");
|
||||||
|
suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T)));
|
||||||
|
suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T)));
|
||||||
|
suite.addTest(copyOnWriteSuite("CopyOnWriteArrayList", T -> new CopyOnWriteObjectArrayList<>(T)));
|
||||||
|
suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T)));
|
||||||
|
suite.addTest(intSuite("IntArrayList", IntArrayList::new));
|
||||||
|
suite.addTest(intSuite("IntLinkedList", IntLinkedList::new));
|
||||||
|
suite.addTest(intCopyOnWriteSuite("CopyOnWriteArrayList", CopyOnWriteIntArrayList::new));
|
||||||
|
suite.addTest(intImmutableSuite("IntImmutableList", ImmutableIntList::new));
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intSuite(String name, Function<int[], IntList> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intCopyOnWriteSuite(String name, Function<int[], IntList> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).suppressing(suppressForCopyOnWriteArrayList()).withFeatures(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intImmutableSuite(String name, Function<int[], IntList> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).withFeatures(CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite(String name, Function<String[], List<String>> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||||
|
@Override
|
||||||
|
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test copyOnWriteSuite(String name, Function<String[], List<String>> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||||
|
@Override
|
||||||
|
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).suppressing(suppressForCopyOnWriteArrayList()).withFeatures(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test immutableSuite(String name, Function<String[], List<String>> factory) {
|
||||||
|
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||||
|
@Override
|
||||||
|
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<Method> suppressForCopyOnWriteArrayList() {
|
||||||
|
return Arrays.asList(ListSubListTester.getSubListSubListRemoveAffectsOriginalLargeListMethod(), ListListIteratorTester.getListIteratorFullyModifiableMethod());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package speiger.src.collections.objects.list;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.SampleElements;
|
||||||
|
import com.google.common.collect.testing.SampleElements.Ints;
|
||||||
|
import com.google.common.collect.testing.TestListGenerator;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.lists.IntList;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class TestIntListGenerator implements TestListGenerator<Integer>
|
||||||
|
{
|
||||||
|
Function<int[], IntList> function;
|
||||||
|
|
||||||
|
public TestIntListGenerator(Function<int[], IntList> function)
|
||||||
|
{
|
||||||
|
this.function = function;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SampleElements<Integer> samples()
|
||||||
|
{
|
||||||
|
return new Ints();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> create(Object... elements)
|
||||||
|
{
|
||||||
|
int[] array = new int[elements.length];
|
||||||
|
int i = 0;
|
||||||
|
for(Object e : elements)
|
||||||
|
{
|
||||||
|
array[i++] = ((Integer)e).intValue();
|
||||||
|
}
|
||||||
|
return function.apply(array);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Integer[] createArray(int length)
|
||||||
|
{
|
||||||
|
return new Integer[length];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> order(List<Integer> insertionOrder)
|
||||||
|
{
|
||||||
|
return insertionOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package speiger.src.collections.objects.map;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NavigableMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.AnEnum;
|
||||||
|
import com.google.common.collect.testing.MapTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.NavigableMapTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.TestEnumMapGenerator;
|
||||||
|
import com.google.common.collect.testing.TestStringMapGenerator;
|
||||||
|
import com.google.common.collect.testing.TestStringSortedMapGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
import com.google.common.collect.testing.features.MapFeature;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.objects.maps.impl.concurrent.Object2ObjectConcurrentOpenHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectLinkedOpenCustomHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectOpenCustomHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.immutable.ImmutableObject2ObjectOpenHashMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.misc.Enum2ObjectMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.misc.LinkedEnum2ObjectMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.misc.Object2ObjectArrayMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectAVLTreeMap;
|
||||||
|
import speiger.src.collections.objects.maps.impl.tree.Object2ObjectRBTreeMap;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ObjectMapTests extends TestCase
|
||||||
|
{
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
TestSuite suite = new TestSuite("Maps");
|
||||||
|
suite.addTest(suite("HashMap", Object2ObjectOpenHashMap::new, true));
|
||||||
|
suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true));
|
||||||
|
suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||||
|
suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||||
|
suite.addTest(suite("ConcurrentHashMap", Object2ObjectConcurrentOpenHashMap::new, true));
|
||||||
|
suite.addTest(navigableSuite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||||
|
suite.addTest(navigableSuite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||||
|
suite.addTest(navigableSuite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<>(new NullFriendlyComparator()), true));
|
||||||
|
suite.addTest(navigableSuite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<>(new NullFriendlyComparator()), true));
|
||||||
|
suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new));
|
||||||
|
suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true));
|
||||||
|
suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class)));
|
||||||
|
suite.addTest(enumSuite("LinkedEnumMap", () -> new LinkedEnum2ObjectMap<>(AnEnum.class)));
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite(String name, Supplier<Map<String, String>> factory, boolean allowNull)
|
||||||
|
{
|
||||||
|
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> create(Map.Entry<String, String>[] entries) {
|
||||||
|
Map<String, String> map = factory.get();
|
||||||
|
for(Map.Entry<String, String> entry : entries) {
|
||||||
|
map.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||||
|
if(allowNull) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||||
|
return builder.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test navigableSuite(String name, Supplier<NavigableMap<String, String>> factory, boolean allowNull)
|
||||||
|
{
|
||||||
|
MapTestSuiteBuilder<String, String> builder = NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {
|
||||||
|
@Override
|
||||||
|
protected NavigableMap<String, String> create(Map.Entry<String, String>[] entries) {
|
||||||
|
NavigableMap<String, String> map = factory.get();
|
||||||
|
for(Map.Entry<String, String> entry : entries) {
|
||||||
|
map.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||||
|
if(allowNull) builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||||
|
return builder.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test immutableSuit(String name, BiFunction<String[], String[], Map<String, String>> factory) {
|
||||||
|
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> create(Map.Entry<String, String>[] entries) {
|
||||||
|
String[] keys = new String[entries.length];
|
||||||
|
String[] values = new String[entries.length];
|
||||||
|
for(int i = 0;i<entries.length;i++) {
|
||||||
|
keys[i] = entries[i].getKey();
|
||||||
|
values[i] = entries[i].getValue();
|
||||||
|
}
|
||||||
|
return factory.apply(keys, values);
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES, MapFeature.ALLOWS_ANY_NULL_QUERIES);
|
||||||
|
return builder.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test enumSuite(String name, Supplier<Map<AnEnum, String>> factory)
|
||||||
|
{
|
||||||
|
MapTestSuiteBuilder<AnEnum, String> builder = MapTestSuiteBuilder.using(new TestEnumMapGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Map<AnEnum, String> create(Map.Entry<AnEnum, String>[] entries) {
|
||||||
|
Map<AnEnum, String> map = factory.get();
|
||||||
|
for(Map.Entry<AnEnum, String> entry : entries) {
|
||||||
|
map.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUPPORTS_ITERATOR_REMOVE);
|
||||||
|
return builder.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class NullFriendlyComparator implements Comparator<String>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(String left, String right) {
|
||||||
|
return String.valueOf(left).compareTo(String.valueOf(right));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Strategy implements ObjectStrategy<String>
|
||||||
|
{
|
||||||
|
static final Strategy INSTANCE = new Strategy();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode(String o) {
|
||||||
|
return Objects.hashCode(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(String key, String value) {
|
||||||
|
return Objects.equals(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package speiger.src.collections.objects.set;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.NavigableSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.NavigableSetTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.SetTestSuiteBuilder;
|
||||||
|
import com.google.common.collect.testing.TestIntegerSetGenerator;
|
||||||
|
import com.google.common.collect.testing.TestStringSetGenerator;
|
||||||
|
import com.google.common.collect.testing.TestStringSortedSetGenerator;
|
||||||
|
import com.google.common.collect.testing.features.CollectionFeature;
|
||||||
|
import com.google.common.collect.testing.features.CollectionSize;
|
||||||
|
import com.google.common.collect.testing.features.SetFeature;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import speiger.src.collections.ints.sets.ImmutableIntOpenHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntAVLTreeSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntArraySet;
|
||||||
|
import speiger.src.collections.ints.sets.IntLinkedOpenCustomHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntLinkedOpenHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntNavigableSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntOpenCustomHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntOpenHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntRBTreeSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntSet;
|
||||||
|
import speiger.src.collections.ints.utils.IntStrategy;
|
||||||
|
import speiger.src.collections.objects.sets.ImmutableObjectOpenHashSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectAVLTreeSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectArraySet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectLinkedOpenCustomHashSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectOpenCustomHashSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectOpenHashSet;
|
||||||
|
import speiger.src.collections.objects.sets.ObjectRBTreeSet;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectStrategy;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public class ObjectSetTests extends TestCase
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static Test suite()
|
||||||
|
{
|
||||||
|
TestSuite suite = new TestSuite("Sets");
|
||||||
|
suite.addTest(intSuite("IntHashSet", IntOpenHashSet::new));
|
||||||
|
suite.addTest(intSuite("IntCustomHashSet", () -> new IntOpenCustomHashSet(IntegerStrategy.INSTANCE)));
|
||||||
|
suite.addTest(intSuite("IntLinkedHashSet", IntLinkedOpenHashSet::new));
|
||||||
|
suite.addTest(intSuite("IntLinkedCustomHashSet", () -> new IntLinkedOpenCustomHashSet(IntegerStrategy.INSTANCE)));
|
||||||
|
suite.addTest(intSuite("IntArraySet", IntArraySet::new));
|
||||||
|
suite.addTest(intImmutableSuite("ImmutableHashSet", ImmutableIntOpenHashSet::new));
|
||||||
|
suite.addTest(intNavigableSuite("IntRBTreeSet", IntRBTreeSet::new));
|
||||||
|
suite.addTest(intNavigableSuite("IntAVLTreeSet", IntAVLTreeSet::new));
|
||||||
|
suite.addTest(suite("HashSet", ObjectOpenHashSet::new, true));
|
||||||
|
suite.addTest(suite("LinkedHashSet", ObjectLinkedOpenHashSet::new, true));
|
||||||
|
suite.addTest(suite("CustomHashSet", T -> new ObjectOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||||
|
suite.addTest(suite("LinkedCustomHashSet", T -> new ObjectLinkedOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
|
||||||
|
suite.addTest(immutableSuite("ImmutableHashSet", ImmutableObjectOpenHashSet::new));
|
||||||
|
suite.addTest(suite("ArraySet", ObjectArraySet::new, true));
|
||||||
|
suite.addTest(navigableSuite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false));
|
||||||
|
suite.addTest(navigableSuite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false));
|
||||||
|
suite.addTest(navigableSuite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||||
|
suite.addTest(navigableSuite("AVLTreeSet_Null", T -> new ObjectAVLTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intSuite(String name, Supplier<IntSet> factory) {
|
||||||
|
SetTestSuiteBuilder<Integer> generator = SetTestSuiteBuilder.using(new TestIntegerSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Set<Integer> create(Integer[] elements) {
|
||||||
|
IntSet set = factory.get();
|
||||||
|
set.addAll(Arrays.asList(elements));
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE);
|
||||||
|
return generator.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intNavigableSuite(String name, Supplier<IntNavigableSet> factory) {
|
||||||
|
SetTestSuiteBuilder<Integer> generator = NavigableSetTestSuiteBuilder.using(new TestIntegerNavigableSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected NavigableSet<Integer> create(Integer[] elements) {
|
||||||
|
IntNavigableSet set = factory.get();
|
||||||
|
set.addAll(Arrays.asList(elements));
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE, CollectionFeature.SUBSET_VIEW);
|
||||||
|
return generator.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test intImmutableSuite(String name, Function<List<Integer>, IntSet> factory) {
|
||||||
|
return SetTestSuiteBuilder.using(new TestIntegerSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Set<Integer> create(Integer[] elements) { return factory.apply(Arrays.asList(elements)); }
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite(String name, Function<String[], Set<String>> factory, boolean allowNull) {
|
||||||
|
SetTestSuiteBuilder<String> generator = SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE);
|
||||||
|
if(allowNull) generator.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||||
|
return generator.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test navigableSuite(String name, Function<String[], NavigableSet<String>> factory, boolean allowNull) {
|
||||||
|
SetTestSuiteBuilder<String> generator = NavigableSetTestSuiteBuilder.using(new TestStringSortedSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected NavigableSet<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE);
|
||||||
|
if(allowNull) generator.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||||
|
return generator.createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test immutableSuite(String name, Function<String[], Set<String>> factory) {
|
||||||
|
return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
|
||||||
|
@Override
|
||||||
|
protected Set<String> create(String[] elements) { return factory.apply(elements); }
|
||||||
|
}).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Strategy implements ObjectStrategy<String> {
|
||||||
|
static final Strategy INSTANCE = new Strategy();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode(String o) {
|
||||||
|
return Objects.hashCode(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(String key, String value) {
|
||||||
|
return Objects.equals(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class IntegerStrategy implements IntStrategy {
|
||||||
|
static final IntegerStrategy INSTANCE = new IntegerStrategy();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode(int o) {
|
||||||
|
return Integer.hashCode(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(int key, int value) {
|
||||||
|
return key == value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package speiger.src.collections.objects.set;
|
||||||
|
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import com.google.common.collect.testing.TestIntegerSortedSetGenerator;
|
||||||
|
import com.google.common.collect.testing.TestSortedSetGenerator;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public abstract class TestIntegerNavigableSetGenerator extends TestIntegerSortedSetGenerator implements TestSortedSetGenerator<Integer>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected abstract SortedSet<Integer> create(Integer[] elements);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortedSet<Integer> create(Object... elements) {
|
||||||
|
Integer[] array = new Integer[elements.length];
|
||||||
|
int i = 0;
|
||||||
|
for (Object e : elements) {
|
||||||
|
array[i++] = (Integer) e;
|
||||||
|
}
|
||||||
|
return create(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer belowSamplesLesser() { return -2; }
|
||||||
|
@Override
|
||||||
|
public Integer belowSamplesGreater() { return -1; }
|
||||||
|
@Override
|
||||||
|
public Integer aboveSamplesLesser() { return 5; }
|
||||||
|
@Override
|
||||||
|
public Integer aboveSamplesGreater() { return 6; }
|
||||||
|
}
|
||||||
@@ -11,7 +11,9 @@ public enum CollectionTest
|
|||||||
REMOVE,
|
REMOVE,
|
||||||
REMOVE_IF,
|
REMOVE_IF,
|
||||||
REMOVE_ALL,
|
REMOVE_ALL,
|
||||||
|
REMOVE_ALL_LISTENER,
|
||||||
RETAIN_ALL,
|
RETAIN_ALL,
|
||||||
|
RETAIN_ALL_LISTENER,
|
||||||
TO_ARRAY,
|
TO_ARRAY,
|
||||||
CLEAR,
|
CLEAR,
|
||||||
WRAPPER,
|
WRAPPER,
|
||||||
|
|||||||
@@ -7,5 +7,15 @@ public enum IterableTest
|
|||||||
ITERATOR_FOR_EACH,
|
ITERATOR_FOR_EACH,
|
||||||
ITERATOR_LOOP,
|
ITERATOR_LOOP,
|
||||||
ITERATOR_REMOVAL,
|
ITERATOR_REMOVAL,
|
||||||
ITERATOR_SKIP;
|
ITERATOR_SKIP,
|
||||||
|
STREAM_COUNT,
|
||||||
|
STREAM_FILTER,
|
||||||
|
STREAM_FIND_FIRST,
|
||||||
|
STREAM_DISTINCT,
|
||||||
|
STREAM_LIMIT,
|
||||||
|
STREAM_MAP,
|
||||||
|
STREAM_MATCHES,
|
||||||
|
STREAM_PEEK,
|
||||||
|
STREAM_POUR,
|
||||||
|
STREAM_REDUCE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public enum ListTest
|
|||||||
ADD_INDEX_COLLECTION,
|
ADD_INDEX_COLLECTION,
|
||||||
ADD_INDEX_LIST,
|
ADD_INDEX_LIST,
|
||||||
ADD_ELEMENTS,
|
ADD_ELEMENTS,
|
||||||
|
ADD_SPECIAL,
|
||||||
INDEX,
|
INDEX,
|
||||||
LAST_INDEX,
|
LAST_INDEX,
|
||||||
GET,
|
GET,
|
||||||
@@ -17,6 +18,7 @@ public enum ListTest
|
|||||||
SORT,
|
SORT,
|
||||||
REPLACE,
|
REPLACE,
|
||||||
REMOVE,
|
REMOVE,
|
||||||
|
REMOVE_SWAP,
|
||||||
REMOVE_ELEMENTS,
|
REMOVE_ELEMENTS,
|
||||||
EXTRACT_ELEMENTS,
|
EXTRACT_ELEMENTS,
|
||||||
LIST_ITERATOR,
|
LIST_ITERATOR,
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package speiger.src.collections.tests;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public enum OrderedMapTests
|
||||||
|
{
|
||||||
|
PUT_MOVE,
|
||||||
|
MOVE,
|
||||||
|
GET_MOVE,
|
||||||
|
FIRST,
|
||||||
|
LAST;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package speiger.src.collections.tests;
|
||||||
|
|
||||||
|
@SuppressWarnings("javadoc")
|
||||||
|
public enum OrderedSetTest
|
||||||
|
{
|
||||||
|
ADD_MOVE,
|
||||||
|
MOVE,
|
||||||
|
PEEK,
|
||||||
|
POLL;
|
||||||
|
}
|
||||||
@@ -3,9 +3,6 @@ package speiger.src.collections.tests;
|
|||||||
@SuppressWarnings("javadoc")
|
@SuppressWarnings("javadoc")
|
||||||
public enum SortedMapTests
|
public enum SortedMapTests
|
||||||
{
|
{
|
||||||
PUT_MOVE,
|
|
||||||
MOVE,
|
|
||||||
GET_MOVE,
|
|
||||||
FIRST,
|
FIRST,
|
||||||
LAST,
|
LAST,
|
||||||
SUB_MAP,
|
SUB_MAP,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user