13 Commits
Author SHA1 Message Date
Speiger 517b84042f Version Bump 2021-12-26 01:58:22 +01:00
Speiger dbfae33074 Fixed Bug with FIFOQueue performance 2021-12-26 00:08:19 +01:00
Speiger ead34009c6 Added pourAsList and pourAsSet 2021-12-25 20:27:33 +01:00
Speiger 7a4a0f05d1 Added subFrom (which is the inverse of addTo) 2021-12-25 20:07:37 +01:00
Speiger 8f32b2d887 Merge remote-tracking branch 'Github/master' 2021-12-25 03:49:45 +01:00
Speiger e6c9600b40 Refactoring and Deprecating SortedMap/Sets
- Added: OrderedMap/Set
- Added: All Relevant functions into Ordered interface
- Changed: Marked all Relevant SortedMap/Set functions Deprecated until
0.6.0
- Fixed: All code that was relevant to this
2021-12-25 03:46:51 +01:00
SpeigerandGitHub d5f2acb9ab Update LICENSE 2021-12-19 21:19:28 +01:00
Speiger 3274e96355 Added Benchmark links 2021-12-16 14:03:39 +01:00
Speiger 78dfa286b0 New Version
- Fixed: Bugs with Queues starting with the wrong size
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
- Added: Benchmarks with java and FastUtil
2021-12-16 13:46:55 +01:00
Speiger f32624d131 Build Release..
-Fixed: Doc error on gradle build.
-Fixed: SubSet.iterator had a ambiguity.
2021-12-14 09:05:25 +01:00
Speiger 59a417056c Added Missing method & fixed potential issue with TreeSetBiIterators 2021-12-13 13:56:28 +01:00
Speiger 18f6704ed7 Expanded Unit tests to IntLists/Sets
Maps are sadly not possible. It will require writing templates for
permutations effectively copying guavas Test library.
So this will take a lot longer
2021-12-13 13:45:35 +01:00
Speiger caf2f22e9f Finished the Basic Unit test frame work to ensure stablity.
-Added: 150k Unit tests.
-Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps
2021-12-13 10:41:20 +01:00
60 changed files with 6241 additions and 4874 deletions
+20
View File
@@ -1,5 +1,25 @@
# Changelog of versions # Changelog of versions
### Version 0.5.3
- Added: OrderedMap/Set
- Added: Deprecation to Functions that are specific to Ordered interfaces in the SortedMap/Set
- Added: subFrom to Maps which is the counterpart of the addTo method
- Added: pourAsList and pourAsSet (booleans excluded for sets) to Iterable
- Fixed: ArrayList.grow had a small bug where it would trigger to early causing performance problems with exact sized collections.
- Fixed: FIFOQueue size constructor had a small bug where it would trigger a array enlargement when all elements were inserted.
### Version 0.5.2
- Fixed: Bugs with Queues starting with the wrong size
- Fixed: ArrayGrowth for Queues was +1 instead of +50%
- Added: Benchmarks with java and FastUtil
### Version 0.5.1
- Fixed: Reworked the NavigableSet/Map implementations of RBTree/AVLTree/Array Sets/Maps so they are now deemed stable.
- Added: Another 150k Unit tests.
- Added: List and Set Unit tests for Integer (or Primitives in this case) to ensure basic stability there. (Now covering all sets and lists)
- Fixed: Bugs with null values for primitive collections.
- Removed: ArraySet/Map subSet/subMap implementation was removed.
### Version 0.5.0 ### Version 0.5.0
- Added: 2 Helper functions to find out how many bits are required to store a Number. - Added: 2 Helper functions to find out how many bits are required to store a Number.
- Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly. - Added: pour function directly into Iterable which allows to collect all elements in the Iterable directly.
+168 -175
View File
@@ -1,208 +1,201 @@
Apache License Apache License
Version 2.0, December 2021
http://www.apache.org/licenses/
Version 2.0, January 2021 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION,
AND DISTRIBUTION
1. Definitions. 1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"License" shall mean the terms and conditions for use, reproduction, and distribution "Licensor" shall mean the copyright owner or entity authorized by
as defined by Sections 1 through 9 of this document. the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"Licensor" shall mean the copyright owner or entity authorized by the copyright "You" (or "Your") shall mean an individual or Legal Entity
owner that is granting the License. exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Legal Entity" shall mean the union of the acting entity and all other entities "Object" form shall mean any form resulting from mechanical
that control, are controlled by, or are under common control with that entity. transformation or translation of a Source form, including but
For the purposes of this definition, "control" means (i) the power, direct not limited to compiled object code, generated documentation,
or indirect, to cause the direction or management of such entity, whether and conversions to other media types.
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
of the outstanding shares, or (iii) beneficial ownership of such entity.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions "Derivative Works" shall mean any work, whether in Source or Object
granted by this License. form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Source" form shall mean the preferred form for making modifications, including "Contributor" shall mean Licensor and any individual or Legal Entity
but not limited to software source code, documentation source, and configuration on behalf of whom a Contribution has been received by Licensor and
files. subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
"Object" form shall mean any form resulting from mechanical transformation 3. Grant of Patent License. Subject to the terms and conditions of
or translation of a Source form, including but not limited to compiled object this License, each Contributor hereby grants to You a perpetual,
code, generated documentation, and conversions to other media types. worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
"Work" shall mean the work of authorship, whether in Source or Object form, (a) You must give any other recipients of the Work or
made available under the License, as indicated by a copyright notice that Derivative Works a copy of this License; and
is included in or attached to the work (an example is provided in the Appendix
below).
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
"Derivative Works" shall mean any work, whether in Source or Object form, (c) You must retain, in the Source form of any Derivative Works
that is based on (or derived from) the Work and for which the editorial revisions, that You distribute, all copyright, patent, trademark, and
annotations, elaborations, or other modifications represent, as a whole, an attribution notices from the Source form of the Work,
original work of authorship. For the purposes of this License, Derivative excluding those notices that do not pertain to any part of
Works shall not include works that remain separable from, or merely link (or the Derivative Works; and
bind by name) to the interfaces of, the Work and Derivative Works thereof.
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
"Contribution" shall mean any work of authorship, including the original version You may add Your own copyright statement to Your modifications and
of the Work and any modifications or additions to that Work or Derivative may provide additional or different license terms and conditions
Works thereof, that is intentionally submitted to Licensor for inclusion in for use, reproduction, or distribution of Your modifications, or
the Work by the copyright owner or by an individual or Legal Entity authorized for any such Derivative Works as a whole, provided Your use,
to submit on behalf of the copyright owner. For the purposes of this definition, reproduction, and distribution of the Work otherwise complies with
"submitted" means any form of electronic, verbal, or written communication the conditions stated in this License.
sent to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor
for the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as "Not a Contribution."
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf 6. Trademarks. This License does not grant permission to use the trade
of whom a Contribution has been received by Licensor and subsequently incorporated names, trademarks, service marks, or product names of the Licensor,
within the Work. except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
2. Grant of Copyright License. Subject to the terms and conditions of this 7. Disclaimer of Warranty. Unless required by applicable law or
License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, agreed to in writing, Licensor provides the Work (and each
no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Contributor provides its Contributions) on an "AS IS" BASIS,
Derivative Works of, publicly display, publicly perform, sublicense, and distribute WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
the Work and such Derivative Works in Source or Object form. implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
3. Grant of Patent License. Subject to the terms and conditions of this License, 8. Limitation of Liability. In no event and under no legal theory,
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, whether in tort (including negligence), contract, or otherwise,
no-charge, royalty-free, irrevocable (except as stated in this section) patent unless required by applicable law (such as deliberate and grossly
license to make, have made, use, offer to sell, sell, import, and otherwise negligent acts) or agreed to in writing, shall any Contributor be
transfer the Work, where such license applies only to those patent claims liable to You for damages, including any direct, indirect, special,
licensable by such Contributor that are necessarily infringed by their Contribution(s) incidental, or consequential damages of any character arising as a
alone or by combination of their Contribution(s) with the Work to which such result of this License or out of the use or inability to use the
Contribution(s) was submitted. If You institute patent litigation against Work (including but not limited to damages for loss of goodwill,
any entity (including a cross-claim or counterclaim in a lawsuit) alleging work stoppage, computer failure or malfunction, or any and all
that the Work or a Contribution incorporated within the Work constitutes direct other commercial damages or losses), even if such Contributor
or contributory patent infringement, then any patent licenses granted to You has been advised of the possibility of such damages.
under this License for that Work shall terminate as of the date such litigation
is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or 9. Accepting Warranty or Additional Liability. While redistributing
Derivative Works thereof in any medium, with or without modifications, and the Work or Derivative Works thereof, You may choose to offer,
in Source or Object form, provided that You meet the following conditions: and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
(a) You must give any other recipients of the Work or Derivative Works a copy END OF TERMS AND CONDITIONS
of this License; and
(b) You must cause any modified files to carry prominent notices stating that APPENDIX: How to apply the Apache License to your work.
You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, To apply the Apache License to your work, attach the following
all copyright, patent, trademark, and attribution notices from the Source boilerplate notice, with the fields enclosed by brackets "[]"
form of the Work, excluding those notices that do not pertain to any part replaced with your own identifying information. (Don't include
of the Derivative Works; and the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
(d) If the Work includes a "NOTICE" text file as part of its distribution, Copyright 2021 Speiger
then any Derivative Works that You distribute must include a readable copy
of the attribution notices contained within such NOTICE file, excluding those
notices that do not pertain to any part of the Derivative Works, in at least
one of the following places: within a NOTICE text file distributed as part
of the Derivative Works; within the Source form or documentation, if provided
along with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works
that You distribute, alongside or as an addendum to the NOTICE text from the
Work, provided that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and may provide Licensed under the Apache License, Version 2.0 (the "License");
additional or different license terms and conditions for use, reproduction, you may not use this file except in compliance with the License.
or distribution of Your modifications, or for any such Derivative Works as You may obtain a copy of the License at
a whole, provided Your use, reproduction, and distribution of the Work otherwise
complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any http://www.apache.org/licenses/LICENSE-2.0
Contribution intentionally submitted for inclusion in the Work by You to the
Licensor shall be under the terms and conditions of this License, without
any additional terms or conditions. Notwithstanding the above, nothing herein
shall supersede or modify the terms of any separate license agreement you
may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, Unless required by applicable law or agreed to in writing, software
trademarks, service marks, or product names of the Licensor, except as required distributed under the License is distributed on an "AS IS" BASIS,
for reasonable and customary use in describing the origin of the Work and WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
reproducing the content of the NOTICE file. See the License for the specific language governing permissions and
limitations under the License.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to
in writing, Licensor provides the Work (and each Contributor provides its
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied, including, without limitation, any warranties
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness
of using or redistributing the Work and assume any risks associated with Your
exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether
in tort (including negligence), contract, or otherwise, unless required by
applicable law (such as deliberate and grossly negligent acts) or agreed to
in writing, shall any Contributor be liable to You for damages, including
any direct, indirect, special, incidental, or consequential damages of any
character arising as a result of this License or out of the use or inability
to use the Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all other commercial
damages or losses), even if such Contributor has been advised of the possibility
of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work
or Derivative Works thereof, You may choose to offer, and charge a fee for,
acceptance of support, warranty, indemnity, or other liability obligations
and/or rights consistent with this License. However, in accepting such obligations,
You may act only on Your own behalf and on Your sole responsibility, not on
behalf of any other Contributor, and only if You agree to indemnify, defend,
and hold each Contributor harmless for any liability incurred by, or claims
asserted against, such Contributor by reason of your accepting any such warranty
or additional liability. END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets "[]" replaced with your own identifying
information. (Don't include the brackets!) The text should be enclosed in
the appropriate comment syntax for the file format. We also recommend that
a file or class name and description of purpose be included on the same "printed
page" as the copyright notice for easier identification within third-party
archives.
Copyright 2021 Speiger
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+13 -13
View File
@@ -6,11 +6,11 @@ But its focus is a different one.
## Main Features: ## Main Features:
- ArrayLists / LinkedLists - ArrayLists / LinkedLists
- 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 - Priority Queues
- Streams & Functional Queries - Streams & Functional Queries
- SplitIterators - SplitIterators
- Iterators - Iterators
@@ -22,17 +22,13 @@ But its focus is a different one.
## Current Level of Stability ## Current Level of Stability
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet. Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 16000 test covering Maps/Sets/Lists. Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 160k unit test covering Maps/Sets/Lists.
These tests cover Javas Collection API completely and ensuring a Stable implementation. These tests cover Javas Collection API completely and ensuring a Stable implementation.
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests). These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
These will be expanded on as time goes on. These will be expanded on as time goes on.
One know aspect of Instability is SubSets and SubMaps. They require full rewrites to be fully stable. ### Benchmarks
So it is not advised to use them until these issues are addressed. Benchmarks can be found here: [Click Me](https://github.com/Speiger/Primitive-Collections-Benchmarks/tree/master)
PriorityQueues are tested separately and ensure basic functionality though GuavaTests are planned.
They just require a custom test implementation.
As a summary: Stability is good/excellent, unless you need SubSets/SubMaps
## Specialized Functions ## Specialized Functions
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life. New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
@@ -47,6 +43,7 @@ To highlight things that may be wanted.
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage. - reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
- pour: a function that allows to collect all elements within the Collection - pour: a function that allows to collect all elements within the Collection
- Collection: - Collection:
- addAll: addAll array version
- containsAny: Allows to test if another collection contains an of the elements of the tested 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. - primitiveStream: Provides access to the closest Java Stream Type.
- copy: shallowCopies the collection, used instead of clone because this is better to use. - copy: shallowCopies the collection, used instead of clone because this is better to use.
@@ -66,6 +63,7 @@ To highlight things that may be wanted.
- putAll: putAll but in Array form. - putAll: putAll but in Array form.
- putAllIfAbsent: Puts only the elements that are absent. - 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) - addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
- subFrom (Only Primitive Values): allows to subtract from the value of a given key. If value reached getDefaultReturnValue() element will be removed.
- addToAll: Same as addTo but bulkVersion. - addToAll: Same as addTo but bulkVersion.
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value. - removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
- mergeAll: BulkVersion of Merge function. - mergeAll: BulkVersion of Merge function.
@@ -95,13 +93,16 @@ repositories {
} }
} }
dependencies { dependencies {
compile 'de.speiger:Primitive-Collections:0.5.0' compile 'de.speiger:Primitive-Collections:0.5.3'
} }
``` ```
Direct: Direct:
| Version | Jar | Sources | Java Doc | | Version | Jar | Sources | Java Doc |
|--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- | |--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- |
| 0.5.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.3/Primitive-Collections-0.5.3-javadoc.jar) |
| 0.5.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.2/Primitive-Collections-0.5.2-javadoc.jar) |
| 0.5.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.1/Primitive-Collections-0.5.1-javadoc.jar) |
| 0.5.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-javadoc.jar) | | 0.5.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.5.0/Primitive-Collections-0.5.0-javadoc.jar) |
| 0.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) | | 0.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) |
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) | | 0.4.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) |
@@ -134,5 +135,4 @@ to build the jar:
do not combine the commands because they can not be executed at the same time. do not combine the commands because they can not be executed at the same time.
## Current Down Sides (Random order) ## Current Down Sides (Random order)
- SubMaps/Set implementation isn't perfect right now. This will be addressed slowly due to rewrites required.
- Documentation is only present at the lowest level for most cases and needs a typo fixing. - Documentation is only present at the lowest level for most cases and needs a typo fixing.
+1 -2
View File
@@ -18,7 +18,7 @@ repositories {
} }
archivesBaseName = 'Primitive Collections' archivesBaseName = 'Primitive Collections'
version = '0.5.0'; version = '0.5.3';
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
@@ -46,7 +46,6 @@ dependencies {
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5' runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.5'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre' testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
} }
task generateSource(type: JavaExec) { task generateSource(type: JavaExec) {
@@ -218,6 +218,7 @@ 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("MAP", "Map", "2"); addBiClassMapper("MAP", "Map", "2");
addClassMapper("NAVIGABLE_SET", "NavigableSet"); addClassMapper("NAVIGABLE_SET", "NavigableSet");
@@ -226,6 +227,7 @@ 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");
@@ -73,7 +73,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", "AbstractMap", "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");
@@ -88,8 +88,8 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
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, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
} }
protected void create(ClassType mainType, ClassType subType) protected void create(ClassType mainType, ClassType subType)
@@ -15,6 +15,12 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.lists.LIST;
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
#if !TYPE_BOOLEAN
import speiger.src.collections.PACKAGE.sets.SET;
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
#endif
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
import speiger.src.collections.PACKAGE.utils.ITERABLES; import speiger.src.collections.PACKAGE.utils.ITERABLES;
import speiger.src.collections.PACKAGE.utils.ITERATORS; import speiger.src.collections.PACKAGE.utils.ITERATORS;
@@ -160,6 +166,24 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
return collection; return collection;
} }
/**
* A Helper function that reduces the usage of streams and allows to collect all elements as a ArrayList
* @return a new ArrayList of all elements
*/
default LIST KEY_GENERIC_TYPE pourAsList() {
return pour(new ARRAY_LISTBRACES());
}
#if !TYPE_BOOLEAN
/**
* A Helper function that reduces the usage of streams and allows to collect all elements as a LinkedHashSet
* @return a new LinkedHashSet of all elements
*/
default SET KEY_GENERIC_TYPE pourAsSet() {
return pour(new LINKED_HASH_SETBRACES());
}
#endif
/** /**
* Helper function to reduce stream usage that allows to filter for any matches. * Helper function to reduce stream usage that allows to filter for any matches.
* @param filter that should be applied * @param filter that should be applied
@@ -232,6 +232,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
* @param index the index where to append the elements to * @param index the index where to append the elements to
* @param c the elements to append to the list * @param c the elements to append to the list
* @throws IndexOutOfBoundsException if index is outside of the lists range * @throws IndexOutOfBoundsException if index is outside of the lists range
* @throws NullPointerException if collection contains a null element
*/ */
@Override @Override
@Primitive @Primitive
@@ -239,6 +240,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;
@@ -1126,7 +1130,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));
} }
@@ -21,6 +21,7 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP; import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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.SORTED_SET;
@@ -71,7 +72,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 SORTED_MAP KEY_VALUE_GENERIC_TYPE, 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;
@@ -286,6 +286,15 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return oldValue; return oldValue;
} }
@Override
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) {
int slot = findIndex(key);
if(slot < 0) return getDefaultReturnValue();
VALUE_TYPE oldValue = values[slot];
values[slot] -= value;
if(value < 0 ? (values[slot] >= getDefaultReturnValue()) : (values[slot] <= getDefaultReturnValue())) removeIndex(slot);
return oldValue;
}
#endif #endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
@Override @Override
@@ -22,6 +22,7 @@ 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.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.SORTED_SET;
import speiger.src.collections.PACKAGE.sets.SET; import speiger.src.collections.PACKAGE.sets.SET;
@@ -70,7 +71,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 SORTED_MAP KEY_VALUE_GENERIC_TYPE, 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;
@@ -261,6 +261,15 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return oldValue; return oldValue;
} }
@Override
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) {
int slot = findIndex(key);
if(slot < 0) return getDefaultReturnValue();
VALUE_TYPE oldValue = values[slot];
values[slot] -= value;
if(value < 0 ? (values[slot] >= getDefaultReturnValue()) : (values[slot] <= getDefaultReturnValue())) removeIndex(slot);
return oldValue;
}
#endif #endif
#if !TYPE_OBJECT #if !TYPE_OBJECT
@Override @Override
@@ -25,6 +25,7 @@ import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
#endif #endif
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; import speiger.src.collections.PACKAGE.maps.interfaces.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; import speiger.src.collections.PACKAGE.sets.SORTED_SET;
@@ -84,7 +85,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 SORTED_MAP KEY_VALUE_GENERIC_TYPE, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{ {
/** The Backing keys array */ /** The Backing keys array */
protected transient KEY_TYPE[] keys; protected transient KEY_TYPE[] keys;
@@ -296,12 +297,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
@Override @Override
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(); }
@@ -180,6 +180,18 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
return getDefaultReturnValue(); return getDefaultReturnValue();
} }
@Override
public VALUE_TYPE subFrom(T key, VALUE_TYPE value) {
int index = key.ordinal();
if(!isSet(index)) return getDefaultReturnValue();
VALUE_TYPE oldValue = values[index];
values[index] -= value;
if(value < 0 ? (values[index] >= getDefaultReturnValue()) : (values[index] <= getDefaultReturnValue())) {
clear(index);
values[index] = EMPTY_VALUE;
}
return oldValue;
}
#endif #endif
@Override @Override
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
@@ -16,6 +16,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
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.ORDERED_MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_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.SORTED_SET;
@@ -42,7 +43,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 SORTED_MAP KEY_VALUE_GENERIC_TYPE, 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;
@@ -179,6 +179,17 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
*/ */
public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m); public void addToAll(MAP KEY_VALUE_GENERIC_TYPE m);
/**
* A Helper method to subtract from primitive from each other. If the key is not present it will just return the defaultValue
* How the implementation works is that it will subtract from the current value (if not present it will do nothing) and fence it to the {@link #getDefaultReturnValue()}
* If the fence is reached the element will be automaticall removed
*
* @param key that should be subtract from
* @param value that should be subtract
* @return the last present or default return value
*/
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value);
#endif #endif
/** /**
* Type Specific function for the bull putting of values * Type Specific function for the bull putting of values
@@ -207,13 +207,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);
@@ -0,0 +1,117 @@
package speiger.src.collections.PACKAGE.maps.interfaces;
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
/**
* 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();
/**
* Creates a Wrapped SortedMap that is Synchronized
* @return a new SortedMap that is synchronized
* @see MAPS#synchronize
*/
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
*/
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
*/
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
}
@@ -19,8 +19,10 @@ 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>, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
{ {
/** /**
* A customized put method that allows you to insert into the first index. * A customized put method that allows you to insert into the first index.
@@ -29,6 +31,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return the previous present or default return value * @return the previous present or default return value
* @see java.util.Map#put(Object, Object) * @see java.util.Map#put(Object, Object)
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#putAndMoveToFirst instead (removed in 0.6.0)
*/ */
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value); public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
/** /**
@@ -38,6 +41,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return the previous present or default return value * @return the previous present or default return value
* @see java.util.Map#put(Object, Object) * @see java.util.Map#put(Object, Object)
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#putAndMoveToLast instead (removed in 0.6.0)
*/ */
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value); public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
@@ -47,6 +51,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return true if the value was moved. * @return true if the value was moved.
* @note returns false if the value was not present in the first place * @note returns false if the value was not present in the first place
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#moveToFirst instead (removed in 0.6.0)
*/ */
public boolean moveToFirst(KEY_TYPE key); public boolean moveToFirst(KEY_TYPE key);
/** /**
@@ -55,6 +60,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @return true if the value was moved. * @return true if the value was moved.
* @note returns false if the value was not present in the first place * @note returns false if the value was not present in the first place
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#moveToLast instead (removed in 0.6.0)
*/ */
public boolean moveToLast(KEY_TYPE key); public boolean moveToLast(KEY_TYPE key);
@@ -63,6 +69,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @param key that is searched for * @param key that is searched for
* @return the given value for the requested key or default return value * @return the given value for the requested key or default return value
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#getAndMoveToFirst instead (removed in 0.6.0)
*/ */
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key); public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
/** /**
@@ -70,6 +77,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
* @param key that is searched for * @param key that is searched for
* @return the given value for the requested key or default return value * @return the given value for the requested key or default return value
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_MAP#getAndMoveToLast instead (removed in 0.6.0)
*/ */
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key); public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
@@ -82,7 +82,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
*/ */
public ARRAY_FIFO_QUEUE(int capacity) { public ARRAY_FIFO_QUEUE(int capacity) {
if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative"); if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative");
array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity)); array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity+1));
minCapacity = array.length; minCapacity = array.length;
} }
@@ -114,8 +114,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
@Override @Override
public void enqueue(KEY_TYPE e) { public void enqueue(KEY_TYPE e) {
array[last] = e; array[last++] = e;
last = ++last % array.length; if(last == array.length) last = 0;
if(last == first) expand(); if(last == first) expand();
} }
@@ -133,7 +133,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;
} }
@@ -153,7 +153,8 @@ 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
@@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.utils.SanityChecks;
/** /**
* A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases. * A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases.
@@ -70,7 +71,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { public ARRAY_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive"); if(size < 0) throw new IllegalAccessError("Size has to be 0 or positive");
if(size > 0) array = NEW_KEY_ARRAY(size); if(size > 0) array = NEW_KEY_ARRAY(size);
this.size = size;
comparator = comp; comparator = comp;
} }
@@ -187,7 +187,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
@Override @Override
public void enqueue(KEY_TYPE e) { public void enqueue(KEY_TYPE e) {
if(size == array.length) array = Arrays.copyOf(array, size+1); if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), 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;
@@ -19,6 +19,7 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
import speiger.src.collections.PACKAGE.functions.function.PREDICATE; import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR; import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
import speiger.src.collections.PACKAGE.utils.ARRAYS; import speiger.src.collections.PACKAGE.utils.ARRAYS;
import speiger.src.collections.utils.SanityChecks;
/** /**
* A Simple Heap base Priority Queue implementation * A Simple Heap base Priority Queue implementation
@@ -66,7 +67,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
*/ */
public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) { public HEAP_PRIORITY_QUEUE(int size, COMPARATOR KEY_SUPER_GENERIC_TYPE comp) {
if(size > 0) array = NEW_KEY_ARRAY(size); if(size > 0) array = NEW_KEY_ARRAY(size);
this.size = size;
comparator = comp; comparator = comp;
} }
@@ -207,7 +207,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
@Override @Override
public void enqueue(KEY_TYPE e) { public void enqueue(KEY_TYPE e) {
if(size == array.length) array = Arrays.copyOf(array, size + 1); if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1));
array[size++] = e; array[size++] = e;
ARRAYS.shiftUp(array, size-1, comparator); ARRAYS.shiftUp(array, size-1, comparator);
} }
File diff suppressed because it is too large Load Diff
@@ -36,7 +36,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 SORTED_SET KEY_GENERIC_TYPE, ORDERED_SET KEY_GENERIC_TYPE
{ {
/** The Backing Array */ /** The Backing Array */
protected transient KEY_TYPE[] data; protected transient KEY_TYPE[] data;
@@ -499,27 +499,30 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
/**
* Unsupported for now. Implementation is buggy and does not support the Java Standard with these functions.
* It is a Unsorted Sorted Set. Thats why the SubSet implementation will be disabled until a better solution is found.
* To give a simple reason: LinkedHashSets are also not SortedSets even so they could be.
* @throws UnsupportedOperationException because it is not supported
*/
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
int fromIndex = findIndex(fromElement); /**
int toIndex = findIndex(toElement); * Unsupported for now. Implementation is buggy and does not support the Java Standard with these functions.
if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException(); * It is a Unsorted Sorted Set. Thats why the SubSet implementation will be disabled until a better solution is found.
return new SubSet(fromIndex, toIndex - fromIndex + 1); * To give a simple reason: LinkedHashSets are also not SortedSets even so they could be.
} * @throws UnsupportedOperationException because it is not supported
*/
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
int toIndex = findIndex(toElement); /**
if(toIndex == -1) throw new NoSuchElementException(); * Unsupported for now. Implementation is buggy and does not support the Java Standard with these functions.
return new SubSet(0, toIndex+1); * It is a Unsorted Sorted Set. Thats why the SubSet implementation will be disabled until a better solution is found.
} * To give a simple reason: LinkedHashSets are also not SortedSets even so they could be.
* @throws UnsupportedOperationException because it is not supported
*/
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
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();
@@ -573,345 +576,346 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
return a; return a;
} }
private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE { // Disabled until a Proper Implementation can be thought out or it is decided that the interface is thrown out.
int offset; // private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
int length; // int offset;
// int length;
SubSet(int offset, int length) { //
this.offset = offset; // SubSet(int offset, int length) {
this.length = length; // this.offset = offset;
} // this.length = length;
// }
int end() { return offset+length; } //
// int end() { return offset+length; }
@Override //
public boolean add(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean add(KEY_TYPE o) {
if(index == -1) { // int index = findIndex(o);
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2); // if(index == -1) {
if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length)); // if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
data[end()] = o; // if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
size++; // data[end()] = o;
length++; // size++;
return true; // length++;
} // return true;
return false; // }
} // return false;
// }
@Override //
public boolean addAndMoveToFirst(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean addAndMoveToFirst(KEY_TYPE o) {
if(index == -1) { // int index = findIndex(o);
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2); // if(index == -1) {
System.arraycopy(data, offset, data, offset+1, size-offset); // if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
data[offset] = o; // System.arraycopy(data, offset, data, offset+1, size-offset);
size++; // data[offset] = o;
length++; // size++;
return true; // length++;
} // return true;
else if(index != 0) { // }
o = data[index]; // else if(index != 0) {
System.arraycopy(data, offset, data, offset+1, index-offset); // o = data[index];
data[offset] = o; // System.arraycopy(data, offset, data, offset+1, index-offset);
} // data[offset] = o;
return false; // }
} // return false;
// }
@Override //
public boolean addAndMoveToLast(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean addAndMoveToLast(KEY_TYPE o) {
if(index == -1) { // int index = findIndex(o);
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2); // if(index == -1) {
System.arraycopy(data, end()+1, data, end(), size-end()); // if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
data[end()] = o; // System.arraycopy(data, end()+1, data, end(), size-end());
size++; // data[end()] = o;
length++; // size++;
return true; // length++;
} // return true;
else if(index != 0) { // }
o = data[index]; // else if(index != 0) {
System.arraycopy(data, offset+1, data, offset, index-offset); // o = data[index];
data[offset+length] = o; // System.arraycopy(data, offset+1, data, offset, index-offset);
} // data[offset+length] = o;
return false; // }
} // return false;
// }
@Override //
public boolean moveToFirst(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean moveToFirst(KEY_TYPE o) {
if(index > offset) { // int index = findIndex(o);
o = data[index]; // if(index > offset) {
System.arraycopy(data, offset, data, offset+1, index-offset); // o = data[index];
data[offset] = o; // System.arraycopy(data, offset, data, offset+1, index-offset);
return true; // data[offset] = o;
} // return true;
return false; // }
} // return false;
// }
@Override //
public boolean moveToLast(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean moveToLast(KEY_TYPE o) {
if(index != -1 && index < end()-1) { // int index = findIndex(o);
o = data[index]; // if(index != -1 && index < end()-1) {
System.arraycopy(data, index+1, data, index, end()-index-1); // o = data[index];
data[end()-1] = o; // System.arraycopy(data, index+1, data, index, end()-index-1);
return true; // data[end()-1] = o;
} // return true;
return false; // }
} // return false;
// }
#if !TYPE_OBJECT //
@Override //#if !TYPE_OBJECT
public boolean contains(KEY_TYPE e) { // @Override
return findIndex(e) != -1; // public boolean contains(KEY_TYPE e) {
} // return findIndex(e) != -1;
// }
#endif //
@Override //#endif
public boolean contains(Object e) { // @Override
return findIndex(e) != -1; // public boolean contains(Object e) {
} // return findIndex(e) != -1;
// }
@Override //
public KEY_TYPE FIRST_KEY() { // @Override
if(length == 0) throw new NoSuchElementException(); // public KEY_TYPE FIRST_KEY() {
return data[offset]; // if(length == 0) throw new NoSuchElementException();
} // return data[offset];
// }
@Override //
public KEY_TYPE LAST_KEY() { // @Override
if(length == 0) throw new NoSuchElementException(); // public KEY_TYPE LAST_KEY() {
return data[end()-1]; // if(length == 0) throw new NoSuchElementException();
} // return data[end()-1];
// }
#if !TYPE_OBJECT //
@Override //#if !TYPE_OBJECT
public boolean remove(KEY_TYPE o) { // @Override
int index = findIndex(o); // public boolean remove(KEY_TYPE o) {
if(index != -1) { // int index = findIndex(o);
size--; // if(index != -1) {
length--; // size--;
if(index != size) System.arraycopy(data, index+1, data, index, size - index); // length--;
return true; // if(index != size) System.arraycopy(data, index+1, data, index, size - index);
} // return true;
return false; // }
} // return false;
// }
#endif //
@Override //#endif
public boolean remove(Object o) { // @Override
int index = findIndex(o); // public boolean remove(Object o) {
if(index != -1) { // int index = findIndex(o);
size--; // if(index != -1) {
length--; // size--;
if(index != size) System.arraycopy(data, index+1, data, index, size - index); // length--;
#if TYPE_OBJECT // if(index != size) System.arraycopy(data, index+1, data, index, size - index);
data[size] = EMPTY_KEY_VALUE; //#if TYPE_OBJECT
#endif // data[size] = EMPTY_KEY_VALUE;
return true; //#endif
} // return true;
return false; // }
} // return false;
// }
@Override //
public KEY_TYPE POLL_FIRST_KEY() { // @Override
if(length == 0) throw new NoSuchElementException(); // public KEY_TYPE POLL_FIRST_KEY() {
size--; // if(length == 0) throw new NoSuchElementException();
length--; // size--;
KEY_TYPE result = data[offset]; // length--;
System.arraycopy(data, offset+1, data, offset, size-offset); // KEY_TYPE result = data[offset];
#if TYPE_OBJECT // System.arraycopy(data, offset+1, data, offset, size-offset);
data[size] = EMPTY_KEY_VALUE; //#if TYPE_OBJECT
#endif // data[size] = EMPTY_KEY_VALUE;
return result; //#endif
} // return result;
// }
@Override //
public KEY_TYPE POLL_LAST_KEY() { // @Override
if(length == 0) throw new NoSuchElementException(); // public KEY_TYPE POLL_LAST_KEY() {
KEY_TYPE result = data[offset+length]; // if(length == 0) throw new NoSuchElementException();
size--; // KEY_TYPE result = data[offset+length];
length--; // size--;
System.arraycopy(data, end()+1, data, end(), size-end()); // length--;
#if TYPE_OBJECT // System.arraycopy(data, end()+1, data, end(), size-end());
data[size] = EMPTY_KEY_VALUE; //#if TYPE_OBJECT
#endif // data[size] = EMPTY_KEY_VALUE;
return result; //#endif
} // return result;
// }
@Override //
public COMPARATOR KEY_GENERIC_TYPE comparator() { // @Override
return null; // public COMPARATOR KEY_GENERIC_TYPE comparator() {
} // return null;
// }
@Override //
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { // @Override
return new SetIterator(offset); // public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
} // return new SetIterator(offset);
// }
@Override //
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { // @Override
int index = findIndex(fromElement); // public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
if(index != -1) return new SetIterator(index); // int index = findIndex(fromElement);
throw new NoSuchElementException(); // if(index != -1) return new SetIterator(index);
} // throw new NoSuchElementException();
// }
@Override //
public SubSet copy() { throw new UnsupportedOperationException(); } // @Override
// public SubSet copy() { throw new UnsupportedOperationException(); }
@Override //
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { // @Override
int fromIndex = findIndex(fromElement); // public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
int toIndex = findIndex(toElement); // int fromIndex = findIndex(fromElement);
if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException(); // int toIndex = findIndex(toElement);
return new SubSet(fromIndex, toIndex - fromIndex + 1); // 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) { // @Override
int toIndex = findIndex(toElement); // public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
if(toIndex == -1) throw new NoSuchElementException(); // int toIndex = findIndex(toElement);
return new SubSet(0, toIndex+1); // if(toIndex == -1) throw new NoSuchElementException();
} // return new SubSet(0, toIndex+1);
// }
@Override //
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { // @Override
int fromIndex = findIndex(fromElement); // public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
if(fromIndex == -1) throw new NoSuchElementException(); // int fromIndex = findIndex(fromElement);
return new SubSet(fromIndex, size - fromIndex); // if(fromIndex == -1) throw new NoSuchElementException();
} // return new SubSet(fromIndex, size - fromIndex);
// }
@Override //
public int size() { // @Override
return length; // public int size() {
} // return length;
// }
#if !TYPE_OBJECT //
@Override //#if !TYPE_OBJECT
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { // @Override
if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end()); // public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
System.arraycopy(data, offset, a, 0, size()); // if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
return a; // System.arraycopy(data, offset, a, 0, size());
} // return a;
// }
#endif //
@Override //#endif
@Deprecated // @Override
public Object[] toArray() { // @Deprecated
Object[] obj = new Object[size()]; // public Object[] toArray() {
for(int i = 0;i<size();i++) // Object[] obj = new Object[size()];
obj[i] = KEY_TO_OBJ(data[offset+i]); // for(int i = 0;i<size();i++)
return obj; // obj[i] = KEY_TO_OBJ(data[offset+i]);
} // return obj;
// }
@Override //
@Primitive // @Override
public <E> E[] toArray(E[] a) { // @Primitive
if(a == null) a = (E[])new Object[size()]; // public <E> E[] toArray(E[] a) {
else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size()); // if(a == null) a = (E[])new Object[size()];
for(int i = 0;i<size();i++) // else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
a[i] = (E)KEY_TO_OBJ(data[offset+i]); // for(int i = 0;i<size();i++)
return a; // a[i] = (E)KEY_TO_OBJ(data[offset+i]);
} // return a;
// }
#if !TYPE_OBJECT //
protected int findIndex(KEY_TYPE o) { //#if !TYPE_OBJECT
for(int i = length-1;i>=0;i--) // protected int findIndex(KEY_TYPE o) {
if(KEY_EQUALS(data[offset+i], o)) return i + offset; // for(int i = length-1;i>=0;i--)
return -1; // if(KEY_EQUALS(data[offset+i], o)) return i + offset;
} // return -1;
// }
#endif //
protected int findIndex(Object o) { //#endif
for(int i = length-1;i>=0;i--) // protected int findIndex(Object o) {
if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset; // for(int i = length-1;i>=0;i--)
return -1; // if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
} // return -1;
// }
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE { //
int index; // private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
int lastReturned = -1; // int index;
// int lastReturned = -1;
public SetIterator(int index) { //
this.index = index; // public SetIterator(int index) {
} // this.index = index;
// }
@Override //
public boolean hasNext() { // @Override
return index < size(); // public boolean hasNext() {
} // return index < size();
// }
@Override //
public KEY_TYPE NEXT() { // @Override
if(!hasNext()) throw new NoSuchElementException(); // public KEY_TYPE NEXT() {
lastReturned = index; // if(!hasNext()) throw new NoSuchElementException();
return data[index++]; // lastReturned = index;
} // return data[index++];
// }
@Override //
public boolean hasPrevious() { // @Override
return index > 0; // public boolean hasPrevious() {
} // return index > 0;
// }
@Override //
public KEY_TYPE PREVIOUS() { // @Override
if(!hasPrevious()) throw new NoSuchElementException(); // public KEY_TYPE PREVIOUS() {
lastReturned = index; // if(!hasPrevious()) throw new NoSuchElementException();
return data[index--]; // lastReturned = index;
} // return data[index--];
// }
@Override //
public int nextIndex() { // @Override
return index; // public int nextIndex() {
} // return index;
// }
@Override //
public int previousIndex() { // @Override
return index-1; // public int previousIndex() {
} // return index-1;
// }
@Override //
public void remove() { // @Override
if(lastReturned == -1) // public void remove() {
throw new IllegalStateException(); // if(lastReturned == -1)
SubSet.this.remove(data[lastReturned]); // throw new IllegalStateException();
if(lastReturned < index) // SubSet.this.remove(data[lastReturned]);
index--; // if(lastReturned < index)
lastReturned = -1; // index--;
} // lastReturned = -1;
// }
#if TYPE_OBJECT //
@Override // #if TYPE_OBJECT
public void set(Object e) { throw new UnsupportedOperationException(); } // @Override
// public void set(Object e) { throw new UnsupportedOperationException(); }
@Override //
public void add(Object e) { throw new UnsupportedOperationException(); } // @Override
// public void add(Object e) { throw new UnsupportedOperationException(); }
#else //
@Override // #else
public void set(KEY_TYPE e) { 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 void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
#endif //
@Override // #endif
public int skip(int amount) { // @Override
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); // public int skip(int amount) {
int steps = Math.min(amount, (size() - 1) - index); // if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
index += steps; // int steps = Math.min(amount, (size() - 1) - index);
return steps; // index += steps;
} // return steps;
// }
@Override //
public int back(int amount) { // @Override
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); // public int back(int amount) {
int steps = Math.min(amount, index); // if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
index -= steps; // int steps = Math.min(amount, index);
return steps; // index -= steps;
} // return steps;
} // }
} // }
// }
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE { private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
int index; int index;
@@ -257,7 +257,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;
@@ -37,7 +37,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 SORTED_SET KEY_GENERIC_TYPE, 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;
@@ -38,7 +38,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 SORTED_SET KEY_GENERIC_TYPE, 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;
@@ -171,10 +171,10 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
default CLASS_TYPE last() { return SORTED_SET.super.last(); } default CLASS_TYPE last() { return SORTED_SET.super.last(); }
@Override @Override
@Deprecated @Deprecated
public default CLASS_TYPE pollFirst() { return KEY_TO_OBJ(POLL_FIRST_KEY()); } public default CLASS_TYPE pollFirst() { return isEmpty() ? null : KEY_TO_OBJ(POLL_FIRST_KEY()); }
@Override @Override
@Deprecated @Deprecated
public default CLASS_TYPE pollLast() { return KEY_TO_OBJ(POLL_LAST_KEY()); } public default CLASS_TYPE pollLast() { return isEmpty() ? null : KEY_TO_OBJ(POLL_LAST_KEY()); }
@Override @Override
@Deprecated @Deprecated
@@ -252,7 +252,12 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
@Override @Override
public boolean contains(Object o) { public boolean contains(Object o) {
#if TYPE_OBJECT
if(o == null) return containsNull; if(o == null) return containsNull;
#else
if(o == null) return false;
if(o instanceof CLASS_TYPE && KEY_EQUALS(CLASS_TO_KEY(o), EMPTY_KEY_VALUE)) return containsNull;
#endif
int pos = HashUtil.mix(o.hashCode()) & mask; int pos = HashUtil.mix(o.hashCode()) & mask;
KEY_TYPE current = keys[pos]; KEY_TYPE current = keys[pos];
if(KEY_EQUALS_NULL(current)) return false; if(KEY_EQUALS_NULL(current)) return false;
@@ -265,7 +270,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;
@@ -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
}
File diff suppressed because it is too large Load Diff
@@ -16,8 +16,10 @@ 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 ORDERED_SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
{ {
/** /**
@@ -26,6 +28,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if it was added * @return true if it was added
* @see java.util.Set#add(Object) * @see java.util.Set#add(Object)
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_SET#addAndMoveToFirst instead (removed in 0.6.0)
*/ */
public boolean addAndMoveToFirst(KEY_TYPE o); public boolean addAndMoveToFirst(KEY_TYPE o);
/** /**
@@ -34,6 +37,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if it was added * @return true if it was added
* @see java.util.Set#add(Object) * @see java.util.Set#add(Object)
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_SET#addAndMoveToLast instead (removed in 0.6.0)
*/ */
public boolean addAndMoveToLast(KEY_TYPE o); public boolean addAndMoveToLast(KEY_TYPE o);
@@ -43,6 +47,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if the value was moved. * @return true if the value was moved.
* @note returns false if the value was not present in the first place * @note returns false if the value was not present in the first place
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_SET#moveToFirst instead (removed in 0.6.0)
*/ */
public boolean moveToFirst(KEY_TYPE o); public boolean moveToFirst(KEY_TYPE o);
/** /**
@@ -51,6 +56,7 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
* @return true if the value was moved. * @return true if the value was moved.
* @note returns false if the value was not present in the first place * @note returns false if the value was not present in the first place
* @note some implementations do not support this method * @note some implementations do not support this method
* @deprecated use ORDERED_SET#moveToLast instead (removed in 0.6.0)
*/ */
public boolean moveToLast(KEY_TYPE o); public boolean moveToLast(KEY_TYPE o);
@@ -18,6 +18,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;
@@ -95,6 +96,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 +162,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
@@ -278,6 +312,39 @@ public class SETS
public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); } public NAVIGABLE_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(n.tailSet(fromElement)); }
} }
private static class UnmodifiableOrderedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
{
ORDERED_SET KEY_GENERIC_TYPE s;
UnmodifiableOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c)
{
super(c);
s = c;
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
@Override
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
@Override
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
@Override
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
@Override
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
@Override
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
}
private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE private static class UnmodifiableSortedSet KEY_GENERIC_TYPE extends UnmodifiableSet KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
{ {
SORTED_SET KEY_GENERIC_TYPE s; SORTED_SET KEY_GENERIC_TYPE s;
@@ -288,47 +355,37 @@ public class SETS
} }
@Override @Override
@Deprecated
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@Deprecated
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@Deprecated
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@Deprecated
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); } public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
@Override @Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); } public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
@Override @Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); } public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); } public SORTED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); } public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { return SETS.unmodifiable(s.subSet(fromElement, toElement)); }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); } public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { return SETS.unmodifiable(s.headSet(toElement)); }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); } public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { return SETS.unmodifiable(s.tailSet(fromElement)); }
@Override @Override
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); } public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
@Override @Override
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); } public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
@Override @Override
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); } public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
@Override @Override
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); } public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
} }
@@ -490,47 +547,96 @@ public class SETS
} }
@Override @Override
@Deprecated
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } } public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
@Override @Override
@Deprecated
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } } public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
@Override @Override
@Deprecated
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } } public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
@Override @Override
@Deprecated
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } } public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
@Override @Override
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } } public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
@Override @Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } } public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
@Override @Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } } public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } } public SORTED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } } public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.subSet(fromElement, toElement), mutex); } }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } } public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { synchronized(mutex) { return SETS.synchronize(s.headSet(toElement), mutex); } }
@Override @Override
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } } public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { synchronized(mutex) { return SETS.synchronize(s.tailSet(fromElement), mutex); } }
@Override @Override
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } } public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
@Override @Override
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } } public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
@Override @Override
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } } public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
@Override
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
}
private static class SynchronizedOrderedTrimSet KEY_GENERIC_TYPE extends SynchronizedOrderedSet KEY_GENERIC_TYPE implements ITrimmable
{
ITrimmable trim;
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c) {
super(c);
trim = (ITrimmable)c;
}
SynchronizedOrderedTrimSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
super(c, mutex);
trim = (ITrimmable)c;
}
@Override
public boolean trim(int size) { synchronized(mutex) { return trim.trim(size); } }
@Override
public void clearAndTrim(int size) { synchronized(mutex) { trim.clearAndTrim(size); } }
}
private static class SynchronizedOrderedSet KEY_GENERIC_TYPE extends SynchronizedSet KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
{
ORDERED_SET KEY_GENERIC_TYPE s;
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c) {
super(c);
s = c;
}
SynchronizedOrderedSet(ORDERED_SET KEY_GENERIC_TYPE c, Object mutex) {
super(c, mutex);
s = c;
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
@Override
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
@Override
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
@Override
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
@Override
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
@Override
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
@Override
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
@Override
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
@Override @Override
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } } public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
} }
@@ -32,6 +32,7 @@ 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;
#if !TYPE_OBJECT #if !TYPE_OBJECT
import speiger.src.collections.PACKAGE.sets.SET; import speiger.src.collections.PACKAGE.sets.SET;
@@ -161,6 +162,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 +215,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 +235,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 +245,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
@@ -262,6 +298,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(); }
@@ -310,6 +348,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(); }
@@ -424,14 +464,14 @@ public class MAPS
} }
/** /**
* 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,6 +489,53 @@ 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 KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
@Override
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
@Override
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
@Override
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
@Override
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
@Override
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
@Override
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
}
/**
* 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
@Deprecated
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
@Deprecated
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
@Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); } public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
@Override @Override
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); } public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { return MAPS.unmodifiable(map.subMap(fromKey, toKey)); }
@@ -494,6 +581,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(); }
@@ -680,6 +769,52 @@ 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() { throw new UnsupportedOperationException(); }
}
/** /**
* 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)
@@ -699,16 +834,22 @@ public class MAPS
} }
@Override @Override
@Deprecated
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } } public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
@Override @Override
@Deprecated
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } } public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
@Override @Override
@Deprecated
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } } public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
@Override @Override
@Deprecated
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } } public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
@Override @Override
@Deprecated
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } } public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
@Override @Override
@Deprecated
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } } 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(); } }
@@ -791,6 +932,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
@@ -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()
{ {
@@ -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();
} }
@@ -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);}
} }
@@ -12,6 +12,10 @@ import com.google.common.collect.testing.features.ListFeature;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
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.ImmutableObjectList; import speiger.src.collections.objects.lists.ImmutableObjectList;
import speiger.src.collections.objects.lists.ObjectArrayList; import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectLinkedList; import speiger.src.collections.objects.lists.ObjectLinkedList;
@@ -25,19 +29,28 @@ public class ObjectListTests extends TestCase
suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T))); suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T)));
suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T))); suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T)));
suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T))); suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T)));
suite.addTest(intSuite("IntArrayList", IntArrayList::new));
suite.addTest(intSuite("IntLinkedList", IntLinkedList::new));
suite.addTest(intImmutableSuite("IntImmutableList", ImmutableIntList::new));
return suite; return suite;
} }
public static Test suite(String name, Function<String[], List<String>> factory) 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 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() { return ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override @Override
protected List<String> create(String[] elements) { return factory.apply(elements); } protected List<String> create(String[] elements) { return factory.apply(elements); }
}).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite(); }).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
} }
public static Test immutableSuite(String name, Function<String[], List<String>> factory) public static Test immutableSuite(String name, Function<String[], List<String>> factory) {
{
return ListTestSuiteBuilder.using(new TestStringListGenerator() { return ListTestSuiteBuilder.using(new TestStringListGenerator() {
@Override @Override
protected List<String> create(String[] elements) { return factory.apply(elements); } protected List<String> create(String[] elements) { return factory.apply(elements); }
@@ -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;
}
}
@@ -2,14 +2,17 @@ package speiger.src.collections.objects.map;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects; import java.util.Objects;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.google.common.collect.testing.AnEnum; import com.google.common.collect.testing.AnEnum;
import com.google.common.collect.testing.MapTestSuiteBuilder; 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.TestEnumMapGenerator;
import com.google.common.collect.testing.TestStringMapGenerator; 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.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize; import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature; import com.google.common.collect.testing.features.MapFeature;
@@ -39,10 +42,10 @@ public class ObjectMapTests extends TestCase
suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true)); suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true));
suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true)); suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true));
suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true)); suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true));
suite.addTest(suite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false)); suite.addTest(navigableSuite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
suite.addTest(suite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false)); suite.addTest(navigableSuite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
suite.addTest(suite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true)); suite.addTest(navigableSuite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<>(new NullFriendlyComparator()), true));
suite.addTest(suite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<String, String>(Comparator.nullsFirst(Comparator.naturalOrder())), true)); suite.addTest(navigableSuite("AVLTreeMap_Null", () -> new Object2ObjectAVLTreeMap<>(new NullFriendlyComparator()), true));
suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new)); suite.addTest(immutableSuit("ImmutableMap", ImmutableObject2ObjectOpenHashMap::new));
suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true)); suite.addTest(suite("ArrayMap", Object2ObjectArrayMap::new, true));
suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class))); suite.addTest(enumSuite("EnumMap", () -> new Enum2ObjectMap<>(AnEnum.class)));
@@ -66,6 +69,22 @@ public class ObjectMapTests extends TestCase
return builder.createTestSuite(); 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) { public static Test immutableSuit(String name, BiFunction<String[], String[], Map<String, String>> factory) {
MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() { MapTestSuiteBuilder<String, String> builder = MapTestSuiteBuilder.using(new TestStringMapGenerator() {
@Override @Override
@@ -97,6 +116,14 @@ public class ObjectMapTests extends TestCase
return builder.createTestSuite(); 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> private static class Strategy implements ObjectStrategy<String>
{ {
static final Strategy INSTANCE = new Strategy(); static final Strategy INSTANCE = new Strategy();
@@ -1,12 +1,19 @@
package speiger.src.collections.objects.set; package speiger.src.collections.objects.set;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.NavigableSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Function; 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.SetTestSuiteBuilder;
import com.google.common.collect.testing.TestIntegerSetGenerator;
import com.google.common.collect.testing.TestStringSetGenerator; 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.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize; import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.SetFeature; import com.google.common.collect.testing.features.SetFeature;
@@ -14,6 +21,17 @@ import com.google.common.collect.testing.features.SetFeature;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; 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.ImmutableObjectOpenHashSet;
import speiger.src.collections.objects.sets.ObjectAVLTreeSet; import speiger.src.collections.objects.sets.ObjectAVLTreeSet;
import speiger.src.collections.objects.sets.ObjectArraySet; import speiger.src.collections.objects.sets.ObjectArraySet;
@@ -27,24 +45,63 @@ import speiger.src.collections.objects.utils.ObjectStrategy;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public class ObjectSetTests extends TestCase public class ObjectSetTests extends TestCase
{ {
@SuppressWarnings("deprecation")
public static Test suite() public static Test suite()
{ {
TestSuite suite = new TestSuite("Sets"); 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("HashSet", ObjectOpenHashSet::new, true));
suite.addTest(suite("LinkedHashSet", ObjectLinkedOpenHashSet::new, true)); suite.addTest(suite("LinkedHashSet", ObjectLinkedOpenHashSet::new, true));
suite.addTest(suite("CustomHashSet", T -> new ObjectOpenCustomHashSet<>(T, Strategy.INSTANCE), 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(suite("LinkedCustomHashSet", T -> new ObjectLinkedOpenCustomHashSet<>(T, Strategy.INSTANCE), true));
suite.addTest(immutableSuite("ImmutableHashSet", ImmutableObjectOpenHashSet::new)); suite.addTest(immutableSuite("ImmutableHashSet", ImmutableObjectOpenHashSet::new));
suite.addTest(suite("ArraySet", ObjectArraySet::new, true)); suite.addTest(suite("ArraySet", ObjectArraySet::new, true));
suite.addTest(suite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false)); suite.addTest(navigableSuite("RBTreeSet_NonNull", ObjectRBTreeSet::new, false));
suite.addTest(suite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false)); suite.addTest(navigableSuite("AVLTreeSet_NonNull", ObjectAVLTreeSet::new, false));
suite.addTest(suite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true)); suite.addTest(navigableSuite("RBTreeSet_Null", T -> new ObjectRBTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
suite.addTest(suite("AVLTreeSet_Null", T -> new ObjectAVLTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true)); suite.addTest(navigableSuite("AVLTreeSet_Null", T -> new ObjectAVLTreeSet<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), true));
return suite; return suite;
} }
public static Test suite(String name, Function<String[], Set<String>> factory, boolean allowNull) 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() { SetTestSuiteBuilder<String> generator = SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override @Override
protected Set<String> create(String[] elements) { return factory.apply(elements); } protected Set<String> create(String[] elements) { return factory.apply(elements); }
@@ -53,17 +110,23 @@ public class ObjectSetTests extends TestCase
return generator.createTestSuite(); 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) public static Test immutableSuite(String name, Function<String[], Set<String>> factory) {
{
return SetTestSuiteBuilder.using(new TestStringSetGenerator() { return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
@Override @Override
protected Set<String> create(String[] elements) { return factory.apply(elements); } protected Set<String> create(String[] elements) { return factory.apply(elements); }
}).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite(); }).named(name).withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite();
} }
private static class Strategy implements ObjectStrategy<String> private static class Strategy implements ObjectStrategy<String> {
{
static final Strategy INSTANCE = new Strategy(); static final Strategy INSTANCE = new Strategy();
@Override @Override
@@ -75,6 +138,20 @@ public class ObjectSetTests extends TestCase
public boolean equals(String key, String value) { public boolean equals(String key, String value) {
return Objects.equals(key, 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;
}
} }
} }
@@ -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; }
}
@@ -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,
@@ -3,8 +3,6 @@ package speiger.src.collections.tests;
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public enum SortedSetTest public enum SortedSetTest
{ {
ADD_MOVE,
MOVE,
PEEK, PEEK,
POLL, POLL,
SUB_SET, SUB_SET,