Compare commits
68
Commits
9557a0cfb5
...
0.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddc58ee221 | ||
|
|
8b5e5a75c1 | ||
|
|
c1862e6b05 | ||
|
|
c2c2780967 | ||
|
|
086d933a0d | ||
|
|
1e7da394a1 | ||
|
|
9eb220194f | ||
|
|
0baf141e4b | ||
|
|
569d4f5c86 | ||
|
|
36f24731b0 | ||
|
|
ea5ace0166 | ||
|
|
663809ff27 | ||
|
|
5d6adb5446 | ||
|
|
212ad1ace2 | ||
|
|
707827929a | ||
|
|
27ad01657d | ||
|
|
e7da7acc08 | ||
|
|
72943cb22c | ||
|
|
068cc4a4f7 | ||
|
|
31b34f5de1 | ||
|
|
4bded1af80 | ||
|
|
100c7fe260 | ||
|
|
04f628fcc1 | ||
|
|
5fa26bfbf3 | ||
|
|
4d3eaaf604 | ||
|
|
33ab7c48bf | ||
|
|
1f4784c75e | ||
|
|
ae5a4ea818 | ||
|
|
5d66f7b453 | ||
|
|
12af656150 | ||
|
|
603ff3df0f | ||
|
|
b712981718 | ||
|
|
863d1a1027 | ||
|
|
6287da8efe | ||
|
|
c27e852ccb | ||
|
|
0157765628 | ||
|
|
8689037ceb | ||
|
|
03a8914986 | ||
|
|
26b9d6706d | ||
|
|
a21d4a9eb6 | ||
|
|
212d614ebd | ||
|
|
bcba3ccde0 | ||
|
|
b42ad76372 | ||
|
|
f95565771a | ||
|
|
3d6cbf5ac1 | ||
|
|
fc5d43e14b | ||
|
|
b3264748cd | ||
|
|
ede40f06d0 | ||
|
|
e69c675f82 | ||
|
|
17c1c90957 | ||
|
|
c6f2f71f6c | ||
|
|
d2c7c151bc | ||
|
|
4448eca787 | ||
|
|
0350a77dff | ||
|
|
4f98c599df | ||
|
|
103b2407d2 | ||
|
|
059da9be12 | ||
|
|
3cac3a997e | ||
|
|
3ffb001c73 | ||
|
|
2810a6f952 | ||
|
|
166362334b | ||
|
|
d3f9103ebf | ||
|
|
1c5507d4a5 | ||
|
|
5e3cd9f484 | ||
|
|
f27b884b6a | ||
|
|
769a9d8ea5 | ||
|
|
9499a7f0e0 | ||
|
|
ca38583f96 |
@@ -15,22 +15,22 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
jdk: [8, 11, 14, 16, 17]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
- name: Set up JDK ${{ matrix.jdk }}
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: gradle
|
||||
java-version: ${{ matrix.jdk }}
|
||||
- name: Validate Gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
||||
- name: Make gradlew executable
|
||||
run: chmod +x ./gradlew
|
||||
- name: Generate SourceCode with Gradle
|
||||
run: ./gradlew generateGithubSource
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
|
||||
@@ -1,8 +1,80 @@
|
||||
# Changelog of versions
|
||||
|
||||
### Version 0.7.0
|
||||
- Added: Over 11 Million Unit Tests to this library to ensure quality.
|
||||
- Added: ArrayList size constructor now throws IllegalStateException if the size parameter is negative
|
||||
- Added: EnumMap specialized forEach implementation.
|
||||
- Added: AbstractMap.remove now delegates to its primitive counterpart.
|
||||
- Added: ConcurrentHashMap now implements ITrimmable
|
||||
- Refactor: Removed a lot of disabled code from ArraySet.
|
||||
- Removed: LinkedList.addAll(index, List) now delegates to LinkedList.addAll(index, Collection) due to no special optimization required.
|
||||
- Fixed: AbstractList.SubList.get/set/swapRemove didn't calculate their List index Properly
|
||||
- Fixed: AbstractList.SubList chains now properly if you create SubLists within SubLists.
|
||||
- Fixed: AbstractList.Iterator.add now respects Immutable/UnmodifiableLists.
|
||||
- Fixed: AbstractList.Iterator.skip/back now keep track of the last returned value for remove function to work properly.
|
||||
- Fixed: CopyOnWriteArrayList.extract/removeElements(int, int) does now proper range checks and remove elements properly.
|
||||
- Fixed: CopyOnWriteArrayList.SubList now works properly. (Reimplemented entirely)
|
||||
- Fixed: CopyOnWriteArrayList.Iterator.previous() was returning the wrong values.
|
||||
- Fixed: CopyOnWriteArrayList.Iterator.skip now skips the right amount of elements and stops where it should.
|
||||
- Fixed: LinkedList.first/last/dequeue/dequeueLast now throws NoSuchElementException when empty instead of IllegalStateException.
|
||||
- Fixed: LinkedList had an edge case where the entire reverse iterator would break if the wrong element was removed.
|
||||
- Fixed: LinkedList.extractElement now returns the correct values.
|
||||
- Fixed: AbstractMap.entrySet().remove(Object) now returns true if defaultReturnValue elements were removed.
|
||||
- Fixed: ConcurrentHashMap.remove(Object, Object) checks if the type matches before comparing against null Values.
|
||||
- Fixed: LinkedHashMap.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||
- Fixed: HashMap.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||
- Fixed: HashMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||
- Fixed: ImmutableMap now compares empty values (0) against nullKeys when Object Variants of the type are used.
|
||||
- Fixed: ArrayMap.iterator(key) now throws NoSuchElementException when the element wasn't found.
|
||||
- Fixed: Linked/EnumMap array constructor was creating the wrong size values array.
|
||||
- Fixed: LinkedEnumMap.getAndMoveToFirst/Last was moving elements even if the element wasn't present.
|
||||
- Fixed: AVL/RBTreeMap.getFirst/LastKey was not throwing a NoSuchElementException if the map was empty.
|
||||
- Fixed: Map.Builder wasn't throwing a IllegalStateException when creating a negative size builder.
|
||||
- Fixed: AVL/RBTreeSet.DecendingSet.subSet(from, fromInclusive, to, toInclusive) was creating a corrupt asending subset.
|
||||
- Fixed: ArraySet throws now a IllegalStateException when trying to create it with a negative size.
|
||||
- Fixed: ArraySet.addMoveToLast(key) was crashing when a key was already present.
|
||||
- Fixed: Immutable/LinkedHashSet now keep track of their iteration index properly.
|
||||
- Fixed: LinkedHashSet.moveToFirst/Last(key) would crash if the Set was empty.
|
||||
- Fixed: LinkedHashSet.clearAndTrim() was checking the wrong value for determining the full reset or clearing of a Map.
|
||||
- Fixed: HashSet.trim/clearToTrim() was using the wrong value to determin if something should be done.
|
||||
|
||||
|
||||
### Version 0.6.2
|
||||
- Added: Array only sorting function return the inputed array. This was done to allow for static final references to use the method in one go without having to make lambda wrappers. Cleaner code.
|
||||
- Added: Iterator Wrappers are now a bit more in Compliance with Java Standards.
|
||||
- Added: AsyncBuilders now Support Array Inputs to create cleaner code.
|
||||
- Changed: LinkedList.addBulk variable definition was triggering a false positive.
|
||||
- Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly.
|
||||
- Fixed: SortedMap.sub/tail/headMap were looping into themselves.
|
||||
- Fixed: AbstractCollection.retainAll didn't push removed values through the consumer.
|
||||
- Fixed: AbstractCollection.toArray wouldn't reset the last entry if the input array was larger then the elements in the collection.
|
||||
- Fixed: SubList didn't check for ranges properly or didn't use parent list to validate changes.
|
||||
- Fixed: ArrayList.addElements didn't check input array fully and used the wrong variable to move the elements around.
|
||||
- Fixed: LinkedList.addElements(EmptyInput) would crash.
|
||||
- Fixed: LinkedList.swapRemove didn't account for if the removed element was the prelast one.
|
||||
- Fixed: LinkedList.removeElements would break the implementation if the list was almost empty and the middle element was removed.
|
||||
- Fixed: LinkedHashSet.addAndMoveToFirst wouldn't move elements to the first place.
|
||||
- Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired.
|
||||
- Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value.
|
||||
- Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests.
|
||||
- Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive.
|
||||
|
||||
|
||||
### Version 0.6.1
|
||||
- Fixed: FIFO queue crashing when the last index is before the first index when peek is called.
|
||||
- Fixed: FIFO queue only clears the array if it was in use.
|
||||
- Added: Sorted Method for the stream replacing functions.
|
||||
|
||||
### Version 0.6.0
|
||||
- Added: addOrGet for sets.
|
||||
- Added: Async API which allows to easily execute Iterables/Collections offthread without the complexity.
|
||||
- Added: CopyOnWriteArrayList and tests for it
|
||||
- Added: Support up to Java17.
|
||||
- Added: Build System now adds module-info if the Running JVM is 9 or higher
|
||||
- Added: ArrayList.of(Class, size) that allows you to allocate a size right at the creation of the List without having to create a wrapper array.
|
||||
- Added: A ConcurrentHashMap implementation.
|
||||
- Fixed: containsValue in the HashMap wouldn't check the nullKey
|
||||
- Removed: Deprecated functions from SortedMaps/Sets
|
||||
|
||||
### Version 0.5.3
|
||||
- Added: OrderedMap/Set
|
||||
|
||||
@@ -1,118 +1,56 @@
|
||||

|
||||
|
||||
[](https://jitpack.io/#Speiger/Primitive-Collections)
|
||||
[](https://opensource.org/licenses/Apache-2.0)
|
||||

|
||||
[](https://codecov.io/gh/Speiger/Primitive-Collections)
|
||||
# Primitive-Collections
|
||||
This is a Simple Primitive Collections Library aimed to outperform Java's Collection Library and FastUtil.
|
||||
Both in Performance and Quality of Life Features.
|
||||
|
||||
This is a Simple Primitive Collections Library i started as a hobby Project.
|
||||
It is based on Java's Collection Library and FastUtil.
|
||||
But its focus is a different one.
|
||||
## Benchmarks
|
||||
Benchmarks can be found here: [[Charts]](https://github.com/Speiger/Primitive-Collections-Benchmarks/blob/master/BENCHMARKS-CHARTS.md), [[Tables]](https://github.com/Speiger/Primitive-Collections-Benchmarks/blob/master/BENCHMARKS.md)
|
||||
|
||||
## Special Features
|
||||
[Here](features.md) you find a set of features added to Primitive Collections.
|
||||
These are designed to improve performance or to provide Quality of Life.
|
||||
|
||||
## Main Features:
|
||||
- ArrayLists / LinkedLists
|
||||
- ArrayLists / LinkedLists / CopyOnWriteLists
|
||||
- HashSets/Maps (Linked & HashControl)
|
||||
- TreeSets/Maps (RB & AVL)
|
||||
- EnumMaps
|
||||
- Immutable Maps/Lists/Sets
|
||||
- ConcurrentHashMaps
|
||||
- Priority Queues
|
||||
- Streams & Functional Queries
|
||||
- SplitIterators
|
||||
- Iterators
|
||||
- Split/Iterators
|
||||
- Pairs
|
||||
- Unary/Functions
|
||||
- Suppliers
|
||||
- Bi/Consumers
|
||||
|
||||
|
||||
## Current Level of Stability
|
||||
Since this is a relatively new Library, stability was not perfect and some areas are not perfect yet.
|
||||
Thanks to [ben-manes](https://github.com/ben-manes) we now have Roughly 160k unit test covering Maps/Sets/Lists.
|
||||
These tests cover Javas Collection API completely and ensuring a Stable implementation.
|
||||
These freshly added tests allowed me to squash thousands of issues according to Googles Test Library (Guava-Tests).
|
||||
These will be expanded on as time goes on.
|
||||
|
||||
### Benchmarks
|
||||
Benchmarks can be found here: [Click Me](https://github.com/Speiger/Primitive-Collections-Benchmarks/tree/master)
|
||||
|
||||
## Specialized Functions
|
||||
New Specialized functions that were added to increase performance or reduce allocations or Quality Of life.
|
||||
To highlight things that may be wanted.
|
||||
- Iterable:
|
||||
- map/flatMap/arrayFlatMap: A Light weight version of Stream.map().
|
||||
- findFirst: Allows to find the first element of a Predicated Iterable.
|
||||
- filter: Allows to filter unwanted elements for wrapped Iterable
|
||||
- matchAny/matchNone/matchAll: Allows to find elements in a collection.
|
||||
- count: counts all valid elements in a collection.
|
||||
- forEach: Allows to input a second element into a forEach move allowing for more flexibility for Method References
|
||||
- reduce/limit/peek/distinct: Light Versions of the Stream variant, to reduce Stream usage.
|
||||
- pour: a function that allows to collect all elements within the Collection
|
||||
- Collection:
|
||||
- addAll: addAll array version
|
||||
- containsAny: Allows to test if another collection contains an of the elements of the tested collection.
|
||||
- primitiveStream: Provides access to the closest Java Stream Type.
|
||||
- copy: shallowCopies the collection, used instead of clone because this is better to use.
|
||||
(subCollections not supported for obvious reasons)
|
||||
- toArray: the ToArray function from Java9 and newer that uses a Functional interface and can use a method reference
|
||||
- List:
|
||||
- add/get/removeElements (From FastUtil): Allows to add/get/remove an Array into/from a list. Just with less overhead
|
||||
- extractElements: Allows to remove a Range of elements from the List and get what was removed.
|
||||
- Unstable Sort(From FastUtil): Uses a faster but not stable sort (Quick-Sort as example) to sort the list.
|
||||
- addIfAbsent/Present: adds a element only if absent/present in the list
|
||||
- swapRemove: deletes a desired element and inserts the last element in its place instead of leftshifting elements.
|
||||
- SortedSet:
|
||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted set.
|
||||
- moveToFirst/Last: Moves the desired element at the first/last position of the SortedSet.
|
||||
- pollFirst/Last: Allows to poll the first/last element of the set.
|
||||
- Map:
|
||||
- putAll: putAll but in Array form.
|
||||
- putAllIfAbsent: Puts only the elements that are absent.
|
||||
- addTo (Only Primitives Values) (From FastUtil but moved to Interface): allows to add to the value of a given key. If not present it will be added. (Accumulator)
|
||||
- subFrom (Only Primitive Values): allows to subtract from the value of a given key. If value reached getDefaultReturnValue() element will be removed.
|
||||
- addToAll: Same as addTo but bulkVersion.
|
||||
- removeOrDefault: removes a Element and if not present returns the default value instead of the present value.
|
||||
- mergeAll: BulkVersion of Merge function.
|
||||
- supplyIfAbsent: A Supplier based computeIfAbsent
|
||||
- Sorted Map:
|
||||
- addAndMoveToFirst/Last (From FastUtil but moved to Interface): Allows to add a element to the first/last position of a sorted Map.
|
||||
- moveToFirst/Last: Moves the desired element at the first/last position of the Map.
|
||||
- getAndMoveToFirst/Last: gets the element and moves it to the first/last position. Replicating a Optional LinkedHashMap feature.
|
||||
- pollFirst/LastKey: Allows to poll the first/last element.
|
||||
- first/LastValue: Allows to get the first/last value from the Map.
|
||||
|
||||
- AsyncBuilders
|
||||
|
||||
# Notes about Versions
|
||||
Any 0.x.0 version (Minor) can be reason for massive changes including API.
|
||||
To ensure that problems can be dealt with even if it is breaking the current API.
|
||||
Any breaking changes will be Documented (once 1.0 is released)
|
||||
|
||||
Also to save space every 0.0.x (Patch) that is 2 Minor Versions behind will be removed.
|
||||
So if 0.5.0 is released every 0.3.x patch will be deleted, except for the last patch for that minor version.
|
||||
|
||||
# How to install
|
||||
Using Gradle:
|
||||
Using Jitpack Gradle
|
||||
```gradle
|
||||
repositories {
|
||||
maven {
|
||||
url = "https://maven.speiger.com/repository/main"
|
||||
url = "https://jitpack.io"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
compile 'de.speiger:Primitive-Collections:0.5.3'
|
||||
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||
}
|
||||
```
|
||||
Direct:
|
||||
|
||||
| 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.4.5 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.5/Primitive-Collections-0.4.5-javadoc.jar) |
|
||||
| 0.4.4 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.4/Primitive-Collections-0.4.4-javadoc.jar) |
|
||||
| 0.4.3 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.3/Primitive-Collections-0.4.3-javadoc.jar) |
|
||||
| 0.4.2 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.2/Primitive-Collections-0.4.2-javadoc.jar) |
|
||||
| 0.4.1 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.1/Primitive-Collections-0.4.1-javadoc.jar) |
|
||||
| 0.4.0 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.4.0/Primitive-Collections-0.4.0-javadoc.jar) |
|
||||
| 0.3.6 | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-sources.jar) | [Download](https://maven.speiger.com/repository/main/de/speiger/Primitive-Collections/0.3.6/Primitive-Collections-0.3.6-javadoc.jar) |
|
||||
# SourceCode
|
||||
The generated Sourcecode can be automatically build,
|
||||
but if you want to just browse around in it.
|
||||
Check out the [Debug Branch](https://github.com/Speiger/Primitive-Collections/tree/debug/src/main/java/speiger/src/collections), which has the entire up to date code.
|
||||
|
||||
# Contributing
|
||||
If you want to contribute.
|
||||
@@ -132,9 +70,5 @@ Please if you want to contribute follow the [Rule-Sheet](RuleSheet.md). It keeps
|
||||
The SourceCode can be generated via:
|
||||
/gradlew.bat generateSource
|
||||
|
||||
to build the jar:
|
||||
to generate SourceCode and build the jar:
|
||||
/gradlew.bat build
|
||||
do not combine the commands because they can not be executed at the same time.
|
||||
|
||||
## Current Down Sides (Random order)
|
||||
- Documentation is only present at the lowest level for most cases and needs a typo fixing.
|
||||
|
||||
+39
-21
@@ -8,7 +8,7 @@ tasks.withType(JavaCompile) {
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -18,9 +18,11 @@ repositories {
|
||||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.5.3';
|
||||
version = '0.7.0';
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||
|
||||
System.out.println("Java Version: "+compileJava.sourceCompatibility)
|
||||
|
||||
javadoc {
|
||||
options.tags = [ "implSpec", "note" ]
|
||||
@@ -42,10 +44,10 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
builderCompile 'de.speiger:Simple-Code-Generator:1.0.6'
|
||||
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.6'
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.1.4'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||
|
||||
}
|
||||
|
||||
task generateSource(type: JavaExec) {
|
||||
@@ -81,6 +83,8 @@ task srcJar(type: Jar) {
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
compileJava.dependsOn generateGithubSource
|
||||
|
||||
javadoc.failOnError = false
|
||||
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
|
||||
javadoc.options.quiet()
|
||||
@@ -94,24 +98,23 @@ test {
|
||||
useJUnit()
|
||||
}
|
||||
|
||||
uploadArchives {
|
||||
publishing {
|
||||
Properties props = new Properties()
|
||||
if(file("$buildDir/credentials.properties").exists())
|
||||
{
|
||||
if(file("$buildDir/credentials.properties").exists()) {
|
||||
props.load(new FileInputStream("$buildDir/credentials.properties"))
|
||||
}
|
||||
repositories.mavenDeployer {
|
||||
repository(url: 'https://maven.speiger.com/repository/main') {
|
||||
authentication(userName: props.mavenUser, password: props.mavenPassword)
|
||||
}
|
||||
snapshotRepository(url: 'https://maven.speiger.com/repository/main') {
|
||||
authentication(userName: props.mavenUser, password: props.mavenPassword)
|
||||
}
|
||||
pom {
|
||||
version = project.version
|
||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||
groupId = 'de.speiger'
|
||||
project {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
pom {
|
||||
name = 'Primitive Collections'
|
||||
description = 'A Primitive Collection library that reduces memory usage and improves performance'
|
||||
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
version = project.version
|
||||
artifactId = project.archivesBaseName.replace(" ", "-")
|
||||
groupId = 'de.speiger'
|
||||
from components.java
|
||||
artifact tasks.srcJar
|
||||
artifact tasks.javadocJar
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache License, Version 2.0'
|
||||
@@ -122,9 +125,24 @@ uploadArchives {
|
||||
developer {
|
||||
id = 'speiger'
|
||||
name = 'Speiger'
|
||||
email = 'speiger@gmx.net'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/Speiger/Primitive-Collections'
|
||||
}
|
||||
issueManagement {
|
||||
system = 'github'
|
||||
url = 'https://github.com/Speiger/Primitive-Collections/issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url version.endsWith('SNAPSHOT') ? "https://maven.speiger.com/repository/debug" : "https://maven.speiger.com/repository/main"
|
||||
credentials(PasswordCredentials) {
|
||||
username props.mavenUser
|
||||
password props.mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+402
@@ -0,0 +1,402 @@
|
||||
## Quality Of Life Features
|
||||
New Specialized functions/classes that were added to increase performance and/or reduce allocations and/or for Quality of life.
|
||||
|
||||
|
||||
# Functions
|
||||
|
||||
Functions that increase performance or are quality of life in their nature.
|
||||
|
||||
<details>
|
||||
<summary>Iterable</summary>
|
||||
<p>
|
||||
|
||||
## Functional Functions
|
||||
|
||||
Java adds themselves a lot of functional functions like,
|
||||
- Stream:
|
||||
- Map/FlatMap
|
||||
- Filter/Distinct/Limit/Sorted
|
||||
- Count/FindFirst/Collect
|
||||
- Peek/ForEach/Reduce
|
||||
- anyMatch/allMatch/NoneMatch
|
||||
|
||||
that allows to process a collection in a functional way.
|
||||
But these require streams which have a lot of Overhead in their nature.
|
||||
|
||||
Luckly Primitive Collections adds replacement functions that provide the same functionality but with minimal overhead.
|
||||
Here are some examples:
|
||||
```java
|
||||
public ObjectIterable<Path> toPath(ObjectIterable<String> iterable) {
|
||||
return iterable.map(Paths::get).filter(Files::exist);
|
||||
}
|
||||
|
||||
public Iterable<Path> toPath(Iterable<String> iterable) {
|
||||
return ObjectIterables.map(iterable, Paths::get).filter(Files::exist);
|
||||
}
|
||||
|
||||
public int sum(IntIterable iterable) {
|
||||
return iterable.reduce(Integer::sum);
|
||||
}
|
||||
```
|
||||
|
||||
## AsyncAPI</summary>
|
||||
|
||||
The AsyncAPI is a Feature that simplifies the processing of Collections on a separate thread.
|
||||
It uses the same concept as Javas Stream API but uses the light weight Functions from Primitive Collections to achieve the same thing.
|
||||
Unlike Javas StreamAPI the AsyncAPI is always singleThreaded and more like Javas CompletableFuture, which you can await or let run Asynchronous.
|
||||
|
||||
The Goal is it to simplify the processing of Collections asynchronous.
|
||||
Especially on tasks which don't have to be finished instantly but can be processed on the side.
|
||||
|
||||
Here is a example of how the API works.
|
||||
```java
|
||||
public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||
potentialFiles.asAsync()
|
||||
.map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
|
||||
.forEach(Files::delete) //Creates the action (Required)
|
||||
.callback(T -> {}} //Callback on completion, still offthread (Optional)
|
||||
.execute() //Starts the task. (Required)
|
||||
}
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
<details>
|
||||
<summary>Collection</summary>
|
||||
<p>
|
||||
|
||||
These are functions specific to the Collections interface, stuff that everyone wished it was present to be in the first place.
|
||||
|
||||
## AddAll (Array)
|
||||
Adding Elements to a Collection usually requires either a for loop or a Arrays.wrap().
|
||||
This isn't an issue with Primitive Collections.
|
||||
```java
|
||||
public void addMonths(ObjectCollection<String> months) {
|
||||
months.addAll("January", "February", "March", "April", "May", "June", "July", "August", "September, "October", November", "December");
|
||||
}
|
||||
|
||||
public void addElements(ObjectCollection<String> result, String[] elements) {
|
||||
result.addAll(elements, 0, 5); //elements, offset, length
|
||||
}
|
||||
```
|
||||
|
||||
## containsAny
|
||||
Everyone hates comparing if 2 collections have part of each other included.
|
||||
The solution usually requires for loops and keeping track if things were found or not.
|
||||
And every Java Developer had this issue at least once and wished for a clean solution.
|
||||
```java
|
||||
public boolean hasMonths(ObjectCollection<Month> target, Collection<Month> toFind) {
|
||||
return target.containsAny(toFind);
|
||||
}
|
||||
```
|
||||
|
||||
## Copy
|
||||
Collections get copied every now and then. There is only 2 ways that this happens.
|
||||
Javas Clone API or using Constructor that supports collections.
|
||||
Javas Clone API is kinda in a Zombie state, where it is supported or not. Its not really clear if you should use it or not.
|
||||
The Clone CloneNotSupportedException isn't helping either, causing more janky code.
|
||||
While a Constructor can only support so much and testing for every case isn't really viable.
|
||||
|
||||
So the decision was made to straight out not support clone and instead add a copy function which doesn't use a checked exception.
|
||||
It works exactly like the clone function. In a sense where it creates a shallow copy. (SubCollections do not work for obvious reasons)
|
||||
```java
|
||||
public IntCollection copy(IntCollection original) {
|
||||
return original.copy();
|
||||
}
|
||||
```
|
||||
|
||||
## Primitive Streams
|
||||
Since Javas Stream API is still really useful, even at its shortcomings, Primitive Collections provides easy access to it.
|
||||
Generic Streams and the closest Primitive Stream will be provided. So a FloatCollection goes to a DoubleStream.
|
||||
```java
|
||||
public IntStream createStream(IntCollection source) {
|
||||
return source.primitiveStream();
|
||||
}
|
||||
```
|
||||
|
||||
## RemoveAll/RetainAll with listener
|
||||
Ever wanted use removeAll or retainAll and wanted to know what elements actually got deleted?
|
||||
The usual solution is to create a copy and then apply it to the original and cross reference them.
|
||||
Which leads to really messy code and just hasn't a clean solution.
|
||||
Luckly Primitive Collections got you covered.
|
||||
```java
|
||||
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toRemove) {
|
||||
files.removeAll(toRemove, T -> System.out.println(T));
|
||||
}
|
||||
|
||||
public void removeInvalidFiles(ObjectCollections<Path> files, ObjectCollection<Path> toKeep) {
|
||||
files.retainFiles(toKeep, T -> System.out.println(T));
|
||||
}
|
||||
```
|
||||
|
||||
## ToArray
|
||||
Primitive Collections supports primitive/generic toArray functions for its Primitive Collections.
|
||||
On top of that the Object side gets a Java9 function ported back to java8, which uses a functional Interface to create the backing array.
|
||||
```java
|
||||
public Integer[] toArray(IntCollection c) {
|
||||
return c.toArray(new Integer[c.size]);
|
||||
}
|
||||
|
||||
public int[] toArray(IntCollection c) {
|
||||
return c.toIntArray();
|
||||
}
|
||||
|
||||
public String[] toArray(ObjectCollection<String> c) {
|
||||
return c.toArray(String::new);
|
||||
}
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>List</summary>
|
||||
<p>
|
||||
|
||||
These functions are List specific functions, a couple of these are from FastUtil.
|
||||
|
||||
## add/get/remove/extractElements
|
||||
These functions really useful helper functions. 3 of which are copied from FastUtil. (extract is from Primitive Collections)
|
||||
They are basically array forms of addAll, getAll, removeRange and removeAndGetRange. This is the simplest way to describe it.
|
||||
|
||||
Here some example:
|
||||
```java
|
||||
public void addAll(DoubleList list) {
|
||||
list.addElements(0D, 12.2D, 3.5D, 4.2D);
|
||||
}
|
||||
|
||||
public double[] getAll(DoubleList list, int amount) {
|
||||
double[] result = new double[amount];
|
||||
list.getElements(0, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void removeRange(FloatList list) {
|
||||
list.removeElements(5, 14);
|
||||
}
|
||||
|
||||
public float[] extractRange(FloatList list) {
|
||||
return list.extractElements(5, 14); //Returns the removed elements
|
||||
}
|
||||
```
|
||||
|
||||
## addIfPresent/addIfAbsent
|
||||
These two functions are simple helper functions that check internally if a element is present or absent before adding them to the List.
|
||||
Removing the need for a contains or indexOf check every time you want to add a element.
|
||||
While it is of course better to use a set, there is cases where this is still useful.
|
||||
|
||||
```java
|
||||
public void addElements(IntList list, int... numbersToAdd) {
|
||||
for(int e : numbersToAdd) {
|
||||
list.addIfAbsent(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addExisting(ObjectList<String> list, String... textToAdd) {
|
||||
for(String s : textToAdd) {
|
||||
list.addIfPresent(s);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## SwapRemove
|
||||
Lists when removing a Element shift usually the backing array to the left based to shrink the elements.
|
||||
While that isn't computational expensive with LinkedLists, it is with ArrayLists.
|
||||
Here comes swapRemove into play, which just removes the desired elements and instead of shifting left puts the last element in its place.
|
||||
This reduces the data copying required down to 1 element instead of an array.
|
||||
|
||||
```java
|
||||
public int remove(IntList elements, int indexToRemove) {
|
||||
return elements.swapRemove(indexToRemove);
|
||||
}
|
||||
```
|
||||
|
||||
## Unstable Sort (From FastUtil)
|
||||
Unstable Sort uses a Faster but not as stable sorting algorithm to sort the Collection.
|
||||
Stable doesn't mean crashing, but more like that the result isn't exactly perfectly sorted.
|
||||
```java
|
||||
public void sort(List<Month> list, Comparator<Month> sorter) {
|
||||
list.unstableSort(sorter);
|
||||
}
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Map</summary>
|
||||
<p>
|
||||
|
||||
These functions are based on the Map interface. Useful functions you really would want.
|
||||
|
||||
## addTo/subFrom
|
||||
addTo (from FastUtil) and subFrom are mathematically functions that either add or subtract from the value of a given key.
|
||||
And if the key isn't present or would result in the default value it will either add or remove the entry from the Map. Given the circumstance.
|
||||
This is a really useful function and I wish FastUtil made it accessible by default but sadly it isn't.
|
||||
To simplify the explanation:
|
||||
- addTo if no element is present puts in the desired number, otherwise it sums up the two values.
|
||||
- subFrom if a element is present subtracts from it, if the element reaches the default value it removes the element from the map. If not present it will be ignored.
|
||||
```java
|
||||
public void addTo(Object2DoubleMap<Month> map, Month key, double averageTrainsRepaired) {
|
||||
map.addTo(key, averageTrainsRepaired);
|
||||
}
|
||||
|
||||
public void subFrom(Long2IntMap map, long key, double amount) {
|
||||
map.subFrom(key, amount);
|
||||
}
|
||||
```
|
||||
|
||||
## addToAll
|
||||
Simple bulk version of the addTo function since sometimes you want to merge 2 maps for summing.
|
||||
Especially if your work is multi-threaded this can become useful.
|
||||
|
||||
```java
|
||||
public void addTo(Object2DoubleMap<Month> map, Object2DoubleMap<Month> trainsRepaired) {
|
||||
map.addToAll(trainsRepaired);
|
||||
}
|
||||
```
|
||||
|
||||
## mergeAll
|
||||
This is a simple bulk version of merge since merging 2 maps is more frequent then people might think and leads to cleaner code too.
|
||||
```java
|
||||
public void merge(Long2ByteMap result, Long2ByteMap toMerge) {
|
||||
result.mergeAll(toMerge);
|
||||
}
|
||||
```
|
||||
|
||||
## putAll (Array)
|
||||
This allows to put keys and values as arrays instead of requiring a WrapperMap to insert the elements.
|
||||
Not as useful as the Collections.addAll variant but still really useful.
|
||||
```java
|
||||
public void putAll(Int2DoubleMap map, int[] keys, double[] values) {
|
||||
map.put(keys, values, 2, 15);
|
||||
}
|
||||
```
|
||||
|
||||
## putAllIfAbsent
|
||||
putAll has this usual quirk where if a element is present it will replace the value, and sometimes this is not wanted.
|
||||
While putIfAbsent exists it has no real mass form and makes iterative solutions really uneasy to use.
|
||||
Here comes the helper function that gets rid of that problem.
|
||||
```java
|
||||
public void merge(Long2ObjectMap<String> regionFiles, Long2ObjectMap<String> toAdd) {
|
||||
regionFiles.putAllIfAbsent(toAdd);
|
||||
}
|
||||
```
|
||||
|
||||
## removeOrDefault
|
||||
getOrDefault is a really useful function that find use cases all the time.
|
||||
Sadly by default there is no variant of removeOrDefault, while it has less cases still could be used every now and then.
|
||||
This function basically tries to remove a element, if it is not present it will just return your desired default.
|
||||
```java
|
||||
public Path removeCache(Long2ObjectMap<Path> caches, long key) {
|
||||
return caches.removeOrDefault(key, Paths.get("nuclearFun"));
|
||||
}
|
||||
```
|
||||
|
||||
## supplyIfAbsent
|
||||
This one is one of my favorites. computeIfAbsent is a really useful function.
|
||||
But in 90% of the cases I use it the value is a collection.
|
||||
This becomes really annoying since methodReferences are faster/cleaner then Lambdas in my opinion.
|
||||
supplyIfAbsent is basically computeIfAbsent but without a key, perfect for the default constructor of a collection.
|
||||
This is the whole reason it exists.
|
||||
```java
|
||||
public void example(Int2ObjectMap<List<String>> map, Int2ObjectMap<String> toAdd) {
|
||||
for(Entry<String> entry : toAdd.entrySet()) {
|
||||
map.supplyIfAbsent(entry.getKey(), ObjectArrayList::new).add(entry.getValue());
|
||||
}
|
||||
}
|
||||
```
|
||||
</p>
|
||||
</details>
|
||||
|
||||
# Interfaces
|
||||
|
||||
Interfaces that provide essential or quality of life features.
|
||||
|
||||
<details>
|
||||
<summary>ITrimmable</summary>
|
||||
<p>
|
||||
|
||||
The ITrimmable is Accessor interface that allows you to access a couple helper functions to control the size of your collections.
|
||||
This was created for the constant casting requirement to implementations just to shrink collections which get annoying over time.
|
||||
|
||||
## trim
|
||||
This function basically trims down the backing implementation to use as little memory as required to store the elements in the collection.
|
||||
Optionally a desired minimum size can be provided as of how low it should go at worst.
|
||||
|
||||
## clearAndTrim
|
||||
when you want to reset a Collection completely you have 2 options. Clear it and then call trim, or recreate the collection.
|
||||
clearAndTrim solves this problem by clearing the collection and trimming it in one go, reducing overhead to achieve such a thing.
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>IArray</summary>
|
||||
<p>
|
||||
|
||||
IArray is a Accessor interface that provides more access to collections by providing tools to grow your collection as needed.
|
||||
While putAll/addAll try to ensure that you have enough room for your elements, this is not really a solution for all cases.
|
||||
Sometimes you need to ensure the Collection is pre-initialized.
|
||||
IArray grants you that control.
|
||||
|
||||
There is also a type specific that provides you access to the backing array implementation of Lists for faster Iteration but that is a really specific case.
|
||||
|
||||
## ensureCapacity
|
||||
Ensures that your collection has enough storage for the elements you want to insert.
|
||||
|
||||
## elements (ITypeSpecificArray)
|
||||
Allows you access to the backing array of a List which is for people who know what they are doing.
|
||||
There is a lambda version of this function too which makes sure for synchronizedLists that you are the only one accessing the array.
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>OrderedMap</summary>
|
||||
<p>
|
||||
|
||||
The OrderedMap is a real edge case interface that was born for a need.
|
||||
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||
They didn't fit into something like a SortedMap because the Set wasn't sorted.
|
||||
So OrderedMap was born, which isn't random but ordered in a specific way that can be changed.
|
||||
|
||||
## getAndMoveToFirst/getAndMoveToLast
|
||||
Returns a desired element and removing it to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||
|
||||
## moveToFirst/moveToLast
|
||||
Moves the element if present to the first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||
Returns true if the element was actually moved.
|
||||
|
||||
## putAndMoveToFirst/putAndMoveToLast
|
||||
Adds the desired element and moves it to first/last spot in the Map. Moving the element that was at its spot after/before it.
|
||||
|
||||
## firstKey/lastKey (Optional poll)
|
||||
Provides access to the current first/last key of the Map.
|
||||
Optionally can be polled if desired.
|
||||
|
||||
## firstValue/lastValue
|
||||
Provides access to the current first/last value of the Map.
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>OrderedSet</summary>
|
||||
<p>
|
||||
|
||||
The OrderedSet is a real edge case interface that was born for a need.
|
||||
FastUtil added functions that were like moveToFirst which were hardcoded to the implementation.
|
||||
They didn't fit into something like a SortedSet because the Set wasn't sorted.
|
||||
So OrderedSet was born, which isn't random but ordered in a specific way that can be changed.
|
||||
|
||||
## addAndMoveToFirst/addAndMoveToLast
|
||||
Adds the desired element and moves it to first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||
|
||||
## moveToFirst/moveToLast
|
||||
Moves the element if present to the first/last spot in the Collection. Moving the element that was at its spot after/before it.
|
||||
Returns true if the element was actually moved.
|
||||
|
||||
## first/last (Optional poll)
|
||||
Provides access to the current first/last element of the set.
|
||||
Optionally can be polled if desired.
|
||||
|
||||
</p>
|
||||
</details>
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
jdk:
|
||||
- openjdk9
|
||||
install:
|
||||
- chmod +x ./gradlew
|
||||
- ./gradlew build publishToMavenLocal
|
||||
|
||||
@@ -158,6 +158,7 @@ public class GlobalVariables
|
||||
|
||||
//Final Classes
|
||||
addClassMapper("ARRAY_LIST", "ArrayList");
|
||||
addAbstractMapper("COPY_ON_WRITE_LIST", "CopyOnWrite%sArrayList");
|
||||
addClassMapper("ASYNC_BUILDER", "AsyncBuilder");
|
||||
addClassMapper("LINKED_LIST", "LinkedList");
|
||||
addAbstractMapper("IMMUTABLE_LIST", "Immutable%sList");
|
||||
@@ -173,6 +174,7 @@ public class GlobalVariables
|
||||
addBiClassMapper("LINKED_CUSTOM_HASH_MAP", "LinkedOpenCustomHashMap", "2");
|
||||
addBiClassMapper("LINKED_HASH_MAP", "LinkedOpenHashMap", "2");
|
||||
addBiClassMapper("CUSTOM_HASH_MAP", "OpenCustomHashMap", "2");
|
||||
addBiClassMapper("CONCURRENT_HASH_MAP", "ConcurrentOpenHashMap", "2");
|
||||
addBiClassMapper("AVL_TREE_MAP", "AVLTreeMap", "2");
|
||||
addBiClassMapper("RB_TREE_MAP", "RBTreeMap", "2");
|
||||
addFunctionValueMappers("LINKED_ENUM_MAP", valueType.isObject() ? "LinkedEnum2ObjectMap" : "LinkedEnum2%sMap");
|
||||
@@ -222,6 +224,7 @@ public class GlobalVariables
|
||||
addBiClassMapper("NAVIGABLE_MAP", "NavigableMap", "2");
|
||||
addBiClassMapper("ORDERED_MAP", "OrderedMap", "2");
|
||||
addBiClassMapper("SORTED_MAP", "SortedMap", "2");
|
||||
addBiClassMapper("CONCURRENT_MAP", "ConcurrentMap", "2");
|
||||
addBiClassMapper("MAP", "Map", "2");
|
||||
addClassMapper("NAVIGABLE_SET", "NavigableSet");
|
||||
addBiClassMapper("PAIR", "Pair", "");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
@@ -10,7 +12,9 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import speiger.src.builder.processor.TemplateProcess;
|
||||
import speiger.src.builder.processor.TemplateProcessor;
|
||||
@@ -65,6 +69,23 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterFinish()
|
||||
{
|
||||
if(getVersion() > 8)
|
||||
{
|
||||
Path basePath = Paths.get("src/main/java");
|
||||
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
|
||||
{
|
||||
writer.write(getModuleInfo(basePath));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
@@ -83,7 +104,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
biRequired.put("Pair", "");
|
||||
biRequired.put("MutablePair", "");
|
||||
biRequired.put("ImmutablePair", "");
|
||||
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "AbstractMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
addBiClass("Function", "Maps", "Map", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "AbstractMap", "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
nameRemapper.put("BiConsumer", "%sConsumer");
|
||||
nameRemapper.put("IArray", "I%sArray");
|
||||
nameRemapper.put("AbstractMap", "Abstract%sMap");
|
||||
@@ -94,12 +115,13 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
nameRemapper.put("EnumMap", "Enum2%sMap");
|
||||
nameRemapper.put("LinkedEnumMap", "LinkedEnum2%sMap");
|
||||
nameRemapper.put("ImmutableList", "Immutable%sList");
|
||||
nameRemapper.put("CopyOnWriteList", "CopyOnWrite%sArrayList");
|
||||
nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet");
|
||||
nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap");
|
||||
|
||||
addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack");
|
||||
addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet");
|
||||
addBlockage(ClassType.BOOLEAN, "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap");
|
||||
}
|
||||
|
||||
protected void create(ClassType mainType, ClassType subType)
|
||||
@@ -161,6 +183,55 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
return variables;
|
||||
}
|
||||
|
||||
private String getModuleInfo(Path basePath) {
|
||||
StringJoiner joiner = new StringJoiner("\n", "", "\n");
|
||||
try(Stream<Path> stream = Files.walk(getOutputFolder()))
|
||||
{
|
||||
stream.filter(Files::isDirectory)
|
||||
.filter(this::containsFiles)
|
||||
.map(basePath::relativize)
|
||||
.map(Path::toString)
|
||||
.map(this::sanitize)
|
||||
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("/** @author Speiger */\n");
|
||||
builder.append("module ").append(sanitize(basePath.relativize(getOutputFolder()).toString())).append(" {\n");
|
||||
builder.append(joiner.toString()).append("}");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String sanitize(String input)
|
||||
{
|
||||
return input.replace("\\", ".").replace("/", ".");
|
||||
}
|
||||
|
||||
private boolean containsFiles(Path path)
|
||||
{
|
||||
try(Stream<Path> stream = Files.walk(path, 1))
|
||||
{
|
||||
return stream.filter(Files::isRegularFile).findFirst().isPresent();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getVersion()
|
||||
{
|
||||
String version = System.getProperty("java.version");
|
||||
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
|
||||
int dot = version.indexOf(".");
|
||||
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
|
||||
}
|
||||
|
||||
public static void main(String...args)
|
||||
{
|
||||
try
|
||||
|
||||
+2
-2
@@ -7,7 +7,6 @@ import java.util.AbstractCollection;
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@@ -100,7 +99,6 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
* This implementation iterates over the elements of the collection and checks if they are stored in this collection
|
||||
* @param c the elements that should be checked for
|
||||
* @return true if any element is in this collection
|
||||
* @deprecated if this is a primitive collection
|
||||
* @throws java.lang.NullPointerException if the collection is null
|
||||
*/
|
||||
@Override
|
||||
@@ -232,6 +230,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) {
|
||||
KEY_TYPE e = iter.NEXT();
|
||||
if(!c.contains(e)) {
|
||||
r.accept(e);
|
||||
iter.remove();
|
||||
modified = true;
|
||||
}
|
||||
@@ -258,6 +257,7 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a == null || a.length < size()) a = new KEY_TYPE[size()];
|
||||
ITERATORS.unwrap(a, iterator());
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
public default int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Can't go forward");
|
||||
int i = 0;
|
||||
for(;i<amount && hasPrevious();previous(),i++);
|
||||
for(;i<amount && hasPrevious();PREVIOUS(),i++);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -5,16 +5,17 @@ import java.util.function.Consumer;
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#if !TYPE_BOOLEAN
|
||||
@@ -157,6 +158,15 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
|
||||
return ITERABLES.limit(this, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to sort the elements
|
||||
* @param sorter that sorts the elements.
|
||||
* @return a Iterable that is sorted
|
||||
*/
|
||||
default ITERABLE KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return ITERABLES.sorted(this, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function to reduce the usage of Streams and allows to preview elements before they are iterated through
|
||||
* @param action the action that should be applied
|
||||
|
||||
+4
@@ -50,6 +50,10 @@ public interface COMPARATOR extends Comparator<CLASS_TYPE>
|
||||
{
|
||||
COMPARATOR original;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
* @param original that is going to be reversed
|
||||
*/
|
||||
public Reversed(COMPARATOR original) {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
+28
-16
@@ -75,7 +75,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
* The IndexOf implementation iterates over all elements and compares them to the search value.
|
||||
* @param o the value that the index is searched for.
|
||||
* @return index of the value that was searched for. -1 if not found
|
||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
@@ -103,7 +103,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
* The lastIndexOf implementation iterates over all elements and compares them to the search value.
|
||||
* @param o the value that the index is searched for.
|
||||
* @return the last index of the value that was searched for. -1 if not found
|
||||
* @deprecated it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
* @note it is highly suggested not to use this with Primitives because of boxing. But it is still supported because of ObjectComparason that are custom objects and allow to find the contents.
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
@@ -308,14 +308,14 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
SanityChecks.checkArrayCapacity(size, from, length);
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
return list.getElements(from+this.offset, a, offset, length);
|
||||
return list.getElements(from+parentOffset, a, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeElements(int from, int to) {
|
||||
if(to-from <= 0) return;
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
checkAddSubRange(to);
|
||||
list.removeElements(from+parentOffset, to+parentOffset);
|
||||
size -= to - from;
|
||||
}
|
||||
@@ -324,9 +324,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
@Override
|
||||
public <K> K[] extractElements(int from, int to, Class<K> type) {
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
checkAddSubRange(to);
|
||||
K[] result = list.extractElements(from+parentOffset, to+parentOffset, type);
|
||||
size -= to - from;
|
||||
size -= result.length;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -334,9 +334,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
@Override
|
||||
public KEY_TYPE[] extractElements(int from, int to) {
|
||||
checkSubRange(from);
|
||||
checkSubRange(to);
|
||||
checkAddSubRange(to);
|
||||
KEY_TYPE[] result = list.extractElements(from+parentOffset, to+parentOffset);
|
||||
size -= to - from;
|
||||
size -= result.length;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -344,19 +344,25 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
@Override
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
checkSubRange(index);
|
||||
return list.GET_KEY(offset+index);
|
||||
return list.GET_KEY(parentOffset+index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE set(int index, KEY_TYPE element) {
|
||||
checkSubRange(index);
|
||||
return list.set(offset+index, element);
|
||||
return list.set(parentOffset+index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE swapRemove(int index) {
|
||||
checkSubRange(index);
|
||||
KEY_TYPE result = list.swapRemove(index+parentOffset);
|
||||
if(index == size-1) {
|
||||
KEY_TYPE result = list.REMOVE(parentOffset+size-1);
|
||||
size--;
|
||||
return result;
|
||||
}
|
||||
KEY_TYPE result = list.set(index+parentOffset, list.GET_KEY(parentOffset+size-1));
|
||||
list.REMOVE(parentOffset+size-1);
|
||||
size--;
|
||||
return result;
|
||||
}
|
||||
@@ -386,7 +392,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int fromIndex, int toIndex) {
|
||||
SanityChecks.checkArrayCapacity(size, fromIndex, toIndex-fromIndex);
|
||||
return new SubList(list, offset, fromIndex, toIndex);
|
||||
return new SubList(this, offset, fromIndex, toIndex);
|
||||
}
|
||||
|
||||
protected void checkSubRange(int index) {
|
||||
@@ -460,15 +466,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
list.add(index++, e);
|
||||
list.add(index, e);
|
||||
index++;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (list.size() - 1) - index);
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@@ -477,6 +485,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
@@ -540,15 +549,17 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
|
||||
@Override
|
||||
public void add(KEY_TYPE e) {
|
||||
ABSTRACT_LIST.this.add(index++, e);
|
||||
ABSTRACT_LIST.this.add(index, e);
|
||||
index++;
|
||||
lastReturned = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (size() - 1) - index);
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@@ -557,6 +568,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-7
@@ -86,6 +86,7 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
* @param size the minimum initial size of the Backing array
|
||||
*/
|
||||
public ARRAY_LIST(int size) {
|
||||
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||
data = NEW_KEY_ARRAY(size);
|
||||
}
|
||||
|
||||
@@ -188,12 +189,25 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ArrayList with a EmptyObject array of the Type requested
|
||||
* @param c the type of the array
|
||||
* @param size the initial size of the backing array
|
||||
* @Type(T)
|
||||
* @return a typed List
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ARRAY_LIST KEY_GENERIC_TYPE of(Class<KEY_TYPE> c, int size) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
list.data = (KEY_TYPE[])ObjectArrays.newArray(c, size);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Appends the specified element to the end of this list.
|
||||
*
|
||||
* @param e element to be appended to this list
|
||||
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
||||
* @return true (as specified by {@link Collection#add})
|
||||
*/
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) {
|
||||
@@ -311,8 +325,9 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
if(length <= 0) return;
|
||||
checkAddRange(from);
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
grow(size + length);
|
||||
if(from != size) System.arraycopy(data, from, data, from+length, size - length);
|
||||
if(from != size) System.arraycopy(data, from, data, from+length, size - from);
|
||||
size+=length;
|
||||
System.arraycopy(a, offset, data, from, length);
|
||||
}
|
||||
@@ -348,11 +363,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
int length = to - from;
|
||||
if(length <= 0) return;
|
||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||
size -= length;
|
||||
#if TYPE_OBJECT
|
||||
for(int i = 0;i<length;i++)
|
||||
data[i+to] = null;
|
||||
data[i+size] = null;
|
||||
#endif
|
||||
size -= length;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@@ -368,13 +383,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
checkRange(from);
|
||||
checkAddRange(to);
|
||||
int length = to - from;
|
||||
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||
K[] a = ARRAYS.newArray(type, length);
|
||||
if(length <= 0) return a;
|
||||
System.arraycopy(data, from, a, 0, length);
|
||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||
for(int i = 0;i<length;i++)
|
||||
data[i+to] = null;
|
||||
size -= length;
|
||||
for(int i = 0;i<length;i++)
|
||||
data[i+size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
+2176
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -556,7 +556,7 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (size() - 1) - index);
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
return steps;
|
||||
}
|
||||
|
||||
+85
-72
@@ -152,10 +152,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
int length = c.size();
|
||||
if(length == 0) return false;
|
||||
checkAddRange(index);
|
||||
Entry KEY_GENERIC_TYPE next = null;
|
||||
Entry KEY_GENERIC_TYPE prev = null;
|
||||
if(index == size) prev = last;
|
||||
else if(index == 0) next = first;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE prev;
|
||||
if(index == size) {
|
||||
prev = last;
|
||||
next = null;
|
||||
}
|
||||
else if(index == 0) {
|
||||
next = first;
|
||||
prev = null;
|
||||
}
|
||||
else {
|
||||
next = getNode(index);
|
||||
prev = next.prev;
|
||||
@@ -177,30 +183,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c) {
|
||||
int length = c.size();
|
||||
if(length == 0) return false;
|
||||
checkAddRange(index);
|
||||
Entry KEY_GENERIC_TYPE next = null;
|
||||
Entry KEY_GENERIC_TYPE prev = null;
|
||||
if(index == size) prev = last;
|
||||
else if(index == 0) next = first;
|
||||
else {
|
||||
next = getNode(index);
|
||||
prev = next.prev;
|
||||
}
|
||||
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();) {
|
||||
Entry KEY_GENERIC_TYPE entry = new EntryBRACES(iter.NEXT(), prev, null);
|
||||
if(prev == null) first = entry;
|
||||
else prev.next = entry;
|
||||
prev = entry;
|
||||
}
|
||||
if(next == null) last = prev;
|
||||
else {
|
||||
prev.next = next;
|
||||
next.prev = prev;
|
||||
}
|
||||
size += length;
|
||||
return true;
|
||||
return addAll(index, (COLLECTION KEY_GENERIC_TYPE)c); //
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,10 +193,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
int length = c.size();
|
||||
if(length == 0) return false;
|
||||
checkAddRange(index);
|
||||
Entry KEY_GENERIC_TYPE next = null;
|
||||
Entry KEY_GENERIC_TYPE prev = null;
|
||||
if(index == size) prev = last;
|
||||
else if(index == 0) next = first;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE prev;
|
||||
if(index == size) {
|
||||
prev = last;
|
||||
next = null;
|
||||
}
|
||||
else if(index == 0) {
|
||||
next = first;
|
||||
prev = null;
|
||||
}
|
||||
else {
|
||||
next = getNode(index);
|
||||
prev = next.prev;
|
||||
@@ -258,12 +247,19 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) {
|
||||
if(length <= 0) return;
|
||||
SanityChecks.checkArrayCapacity(a.length, offset, length);
|
||||
checkAddRange(from);
|
||||
Entry KEY_GENERIC_TYPE next = null;
|
||||
Entry KEY_GENERIC_TYPE prev = null;
|
||||
if(from == size) prev = last;
|
||||
else if(from == 0) next = first;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE prev;
|
||||
if(from == size) {
|
||||
prev = last;
|
||||
next = null;
|
||||
}
|
||||
else if(from == 0) {
|
||||
next = first;
|
||||
prev = null;
|
||||
}
|
||||
else {
|
||||
next = getNode(from);
|
||||
prev = next.prev;
|
||||
@@ -297,13 +293,13 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public KEY_TYPE first() {
|
||||
if(first == null) throw new IllegalStateException();
|
||||
if(first == null) throw new NoSuchElementException();
|
||||
return first.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE last() {
|
||||
if(last == null) throw new IllegalStateException();
|
||||
if(last == null) throw new NoSuchElementException();
|
||||
return last.value;
|
||||
}
|
||||
|
||||
@@ -536,13 +532,13 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public KEY_TYPE dequeue() {
|
||||
if(first == null) throw new IllegalStateException();
|
||||
if(first == null) throw new NoSuchElementException();
|
||||
return unlinkFirst(first);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE dequeueLast() {
|
||||
if(last == null) throw new IllegalStateException();
|
||||
if(last == null) throw new NoSuchElementException();
|
||||
return unlinkLast(last);
|
||||
}
|
||||
|
||||
@@ -593,12 +589,15 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
first = temp;
|
||||
return result;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
else if(before.next != last) {
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
temp.next.prev = temp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -623,12 +622,15 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
first = temp;
|
||||
return true;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
else if(before.next != last) {
|
||||
Entry KEY_GENERIC_TYPE temp = last;
|
||||
last = temp.prev;
|
||||
last.next = null;
|
||||
temp.next = before.next;
|
||||
temp.prev = before;
|
||||
before.next = temp;
|
||||
temp.next.prev = temp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -671,16 +673,18 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
if(from < size - to) {
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||
while(length > 0) {
|
||||
entry = entry.next;
|
||||
unlink(entry.prev);
|
||||
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||
unlink(entry);
|
||||
entry = next;
|
||||
length--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||
while(length > 0) {
|
||||
entry = entry.prev;
|
||||
unlink(entry.next);
|
||||
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||
unlink(entry);
|
||||
entry = prev;
|
||||
length--;
|
||||
}
|
||||
}
|
||||
@@ -691,20 +695,22 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
checkRange(from);
|
||||
checkAddRange(to);
|
||||
int length = to - from;
|
||||
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||
K[] a = ARRAYS.newArray(type, length);
|
||||
if(length <= 0) return a;
|
||||
if(from < size - to) {
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||
for(int i = 0;length > 0;i++, length--) {
|
||||
entry = entry.next;
|
||||
a[i] = (K)unlink(entry.prev);
|
||||
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||
a[i] = (K)unlink(entry);
|
||||
entry = next;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
||||
for(int i = length-1;length > 0;i--) {
|
||||
entry = entry.prev;
|
||||
a[i] = (K)unlink(entry.next);
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||
for(int i = length-1;length > 0;i--, length--) {
|
||||
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||
a[i] = (K)unlink(entry);
|
||||
entry = prev;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
@@ -720,15 +726,17 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
if(from < size - to) {
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||
for(int i = 0;length > 0;i++, length--) {
|
||||
entry = entry.next;
|
||||
d[i] = unlink(entry.prev);
|
||||
Entry KEY_GENERIC_TYPE next = entry.next;
|
||||
d[i] = unlink(entry);
|
||||
entry = next;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to);
|
||||
for(int i = length-1;length > 0;i--) {
|
||||
entry = entry.prev;
|
||||
d[i] = unlink(entry.next);
|
||||
Entry KEY_GENERIC_TYPE entry = getNode(to-1);
|
||||
for(int i = length-1;length > 0;i--, length--) {
|
||||
Entry KEY_GENERIC_TYPE prev = entry.prev;
|
||||
d[i] = unlink(entry);
|
||||
entry = prev;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
@@ -1106,6 +1114,11 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
this.prev = prev;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return KEY_TO_STRING(value);
|
||||
}
|
||||
}
|
||||
|
||||
private class ListIter implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
@@ -1239,7 +1252,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return list.size - index;
|
||||
return (long)list.size - (long)index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1305,7 +1318,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return list.size - index;
|
||||
return (long)list.size - (long)index;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+15
-1
@@ -285,6 +285,16 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE remove(Object key) {
|
||||
#if TYPE_OBJECT
|
||||
return VALUE_TO_OBJ(REMOVE_VALUE((CLASS_TYPE)key));
|
||||
#else
|
||||
return key instanceof CLASS_TYPE ? VALUE_TO_OBJ(REMOVE_VALUE(CLASS_TO_KEY(key))) : VALUE_TO_OBJ(getDefaultReturnValue());
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@@ -306,7 +316,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
#else
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return VALUE_EQUALS_NOT(ABSTRACT_MAP.this.remove(o), getDefaultReturnValue());
|
||||
if(ABSTRACT_MAP.this.containsKey(o)) {
|
||||
ABSTRACT_MAP.this.remove(o);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+2447
File diff suppressed because it is too large
Load Diff
+14
-58
@@ -1,7 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.customHash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,7 +9,6 @@ import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
@@ -22,10 +20,8 @@ import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
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.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -60,8 +56,7 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
@@ -72,7 +67,7 @@ import speiger.src.collections.utils.HashUtil;
|
||||
* @Type(T)
|
||||
* @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, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected transient long[] links;
|
||||
@@ -289,7 +284,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -311,7 +306,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) {
|
||||
if(strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(isEmpty() || strategy.equals(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -364,20 +359,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
@@ -388,8 +369,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
@@ -412,8 +392,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
lastIndex = (int)(links[pos] >>> 32);
|
||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
@@ -439,15 +418,15 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
return entrySet;
|
||||
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = new KeySet();
|
||||
return keySet;
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -474,7 +453,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -621,7 +600,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -861,20 +840,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
public void clear() {
|
||||
LINKED_CUSTOM_HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -1093,18 +1061,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
|
||||
+19
-6
@@ -316,6 +316,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && VALUE_EQUALS(values[i], value)) return true;
|
||||
return false;
|
||||
@@ -325,7 +326,12 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||
#else
|
||||
if(containsNull && ((value == null && values[nullIndex] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[nullIndex], value))) return true;
|
||||
#endif
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(!strategy.equals(keys[i], EMPTY_KEY_VALUE) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||
#else
|
||||
@@ -388,7 +394,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public boolean remove(Object key, Object value) {
|
||||
Objects.requireNonNull(value);
|
||||
#if TYPE_OBJECT
|
||||
if(key == null) {
|
||||
#else
|
||||
if(key == null || (key instanceof CLASS_TYPE && strategy.equals(CLASS_TO_KEY(key), EMPTY_KEY_VALUE))) {
|
||||
#endif
|
||||
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
||||
removeNullIndex();
|
||||
return true;
|
||||
@@ -622,7 +632,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
if(request >= nullIndex || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
try {
|
||||
rehash(request);
|
||||
}
|
||||
@@ -633,7 +643,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -663,6 +673,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
protected int findIndex(CLASS_TYPE key) {
|
||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
KEY_TYPE keyType = CLASS_TO_KEY(key);
|
||||
#if !TYPE_OBJECT
|
||||
if(strategy.equals(keyType, EMPTY_KEY_VALUE)) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
#endif
|
||||
int pos = HashUtil.mix(strategy.hashCode(keyType)) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(!strategy.equals(current, EMPTY_KEY_VALUE)) {
|
||||
@@ -936,7 +949,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
@@ -1167,7 +1180,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
@@ -1323,7 +1336,7 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
state = values[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
|
||||
+17
-64
@@ -1,7 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.hash;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,7 +9,6 @@ import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
@@ -21,11 +19,9 @@ import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
@@ -59,8 +55,7 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#endif
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
|
||||
@@ -71,7 +66,7 @@ import speiger.src.collections.utils.HashUtil;
|
||||
* @Type(T)
|
||||
* @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, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected transient long[] links;
|
||||
@@ -266,7 +261,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -288,7 +283,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) {
|
||||
if(KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(LAST_ENTRY_KEY(), key)) return false;
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -368,20 +363,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
@@ -392,8 +373,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
@@ -416,8 +396,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
lastIndex = (int)(links[pos] >>> 32);
|
||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
@@ -443,15 +422,15 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
return entrySet;
|
||||
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = new KeySet();
|
||||
return keySet;
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -478,7 +457,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -625,7 +604,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
values = newValues;
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -862,20 +841,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
public void clear() {
|
||||
LINKED_HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -905,9 +873,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@@ -1089,23 +1055,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
int result = 0;
|
||||
int index = firstIndex;
|
||||
while(index != -1){
|
||||
if(filter.TEST_VALUE(keys[index])) return result++;
|
||||
if(filter.TEST_VALUE(keys[index])) result++;
|
||||
index = (int)links[index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -1371,7 +1325,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public void add(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
@@ -1441,7 +1394,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
if(previous == -1) firstIndex = next;
|
||||
else links[previous] ^= ((links[previous] ^ (next & 0xFFFFFFFFL)) & 0xFFFFFFFFL);
|
||||
|
||||
if (next == -1) lastIndex = previous;
|
||||
if(next == -1) lastIndex = previous;
|
||||
else links[next] ^= ((links[next] ^ ((previous & 0xFFFFFFFFL) << 32)) & 0xFFFFFFFF00000000L);
|
||||
if(current == nullIndex) {
|
||||
current = -1;
|
||||
|
||||
+20
-7
@@ -287,7 +287,8 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean containsValue(VALUE_TYPE value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && VALUE_EQUALS(values[i], value)) return true;
|
||||
return false;
|
||||
}
|
||||
@@ -296,7 +297,12 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
@ValuePrimitive
|
||||
public boolean containsValue(Object value) {
|
||||
for(int i = nullIndex;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(containsNull && VALUE_EQUALS(values[nullIndex], value)) return true;
|
||||
#else
|
||||
if(containsNull && ((value == null && values[nullIndex] == getDefaultReturnValue()) || EQUALS_VALUE_TYPE(values[nullIndex], value))) return true;
|
||||
#endif
|
||||
for(int i = nullIndex-1;i >= 0;i--)
|
||||
#if VALUE_OBJECT
|
||||
if(KEY_EQUALS_NOT_NULL(keys[i]) && EQUALS_VALUE_TYPE(values[i], value)) return true;
|
||||
#else
|
||||
@@ -356,7 +362,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public boolean remove(Object key, Object value) {
|
||||
Objects.requireNonNull(value);
|
||||
#if TYPE_OBJECT
|
||||
if(key == null) {
|
||||
#else
|
||||
if(key == null || (key instanceof CLASS_TYPE && KEY_EQUALS_NULL(CLASS_TO_KEY(key)))) {
|
||||
#endif
|
||||
if(containsNull && EQUALS_VALUE_TYPE(values[nullIndex], value)) {
|
||||
removeNullIndex();
|
||||
return true;
|
||||
@@ -583,7 +593,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size || this.size > Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
try {
|
||||
rehash(request);
|
||||
}
|
||||
@@ -594,7 +604,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -623,6 +633,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
#endif
|
||||
protected int findIndex(Object key) {
|
||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
#if !TYPE_OBJECT
|
||||
if(key instanceof CLASS_TYPE && KEY_EQUALS_NULL(CLASS_TO_KEY(key))) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
#endif
|
||||
int pos = HashUtil.mix(key.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
@@ -896,7 +909,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]);
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
@@ -1123,7 +1136,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
@@ -1279,7 +1292,7 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
state = values[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
|
||||
+14
-46
@@ -1,7 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.immutable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
@@ -11,7 +10,6 @@ import java.util.function.BiFunction;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && !VALUE_BOOLEAN
|
||||
@@ -24,11 +22,12 @@ import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.function.SINGLE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
@@ -50,7 +49,6 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -71,10 +69,9 @@ import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOpera
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
#endif
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.utils.HashUtil;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@@ -85,7 +82,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* @Type(T)
|
||||
* @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, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
@@ -104,9 +101,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** The Last Index in the Map */
|
||||
protected int lastIndex = -1;
|
||||
/** EntrySet cache */
|
||||
protected transient FastEntrySet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
protected transient FastOrderedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
/** KeySet cache */
|
||||
protected transient SET KEY_GENERIC_TYPE keySet;
|
||||
protected transient ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
@@ -433,13 +430,13 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
return entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = new KeySet();
|
||||
return keySet;
|
||||
}
|
||||
@@ -465,15 +462,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(KEY_TYPE toKey) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) {
|
||||
int index = firstIndex;
|
||||
@@ -529,6 +517,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
#endif
|
||||
protected int findIndex(Object key) {
|
||||
if(key == null) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
#if !TYPE_OBJECT
|
||||
if(KEY_EQUALS_NULL(CLASS_TO_KEY(key))) return containsNull ? nullIndex : -(nullIndex + 1);
|
||||
#endif
|
||||
int pos = HashUtil.mix(key.hashCode()) & mask;
|
||||
KEY_TYPE current = keys[pos];
|
||||
if(KEY_EQUALS_NOT_NULL(current)) {
|
||||
@@ -597,7 +588,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -810,20 +801,9 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -1024,18 +1004,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
|
||||
+22
-1138
File diff suppressed because it is too large
Load Diff
+13
-4
@@ -4,6 +4,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -76,8 +77,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
@@ -93,8 +94,8 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
@@ -530,6 +531,14 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super MAP.Entry KEY_VALUE_GENERIC_TYPE> action) {
|
||||
if(size() <= 0) return;
|
||||
for(int i = 0,m=keys.length;i<m;i++) {
|
||||
if(isSet(i)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator();
|
||||
|
||||
+17
-58
@@ -1,6 +1,5 @@
|
||||
package speiger.src.collections.PACKAGE.maps.impl.misc;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,17 +9,14 @@ import java.util.Objects;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
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.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
@@ -32,8 +28,6 @@ import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST_ITERATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.lists.ObjectListIterator;
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -43,7 +37,7 @@ import speiger.src.collections.objects.sets.ObjectSet;
|
||||
* @Type(T)
|
||||
* @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, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected long[] links;
|
||||
@@ -72,9 +66,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||
links = new long[this.keys.length];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
@@ -90,9 +84,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
if(keys.length != values.length) throw new IllegalArgumentException("Keys and Values have to be the same size");
|
||||
keyType = keys[0].getDeclaringClass();
|
||||
this.keys = getKeyUniverse(keyType);
|
||||
this.values = NEW_VALUE_ARRAY(keys.length);
|
||||
present = new long[((keys.length - 1) >> 6) + 1];
|
||||
links = new long[keys.length];
|
||||
this.values = NEW_VALUE_ARRAY(this.keys.length);
|
||||
present = new long[((this.keys.length - 1) >> 6) + 1];
|
||||
links = new long[this.keys.length];
|
||||
putAll(keys, values);
|
||||
}
|
||||
|
||||
@@ -245,7 +239,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(T key) {
|
||||
int index = key.ordinal();
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
moveToFirstIndex(index);
|
||||
return values[index];
|
||||
}
|
||||
@@ -253,7 +247,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(T key) {
|
||||
int index = key.ordinal();
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
moveToLastIndex(index);
|
||||
return values[index];
|
||||
}
|
||||
@@ -270,20 +264,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(T fromKey, T toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(T toKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(T fromKey) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public T FIRST_ENTRY_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
@@ -333,15 +313,15 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
return entrySet;
|
||||
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keySet == null) keySet = new KeySet();
|
||||
return keySet;
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -434,7 +414,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
}
|
||||
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements SORTED_MAP.FastSortedSet KEY_VALUE_GENERIC_TYPE {
|
||||
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@@ -559,20 +539,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
public void clear() {
|
||||
LINKED_ENUM_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparator<MAP.Entry KEY_VALUE_GENERIC_TYPE> comparator() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> subSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement, MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> headSet(MAP.Entry KEY_VALUE_GENERIC_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> tailSet(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
||||
private final class KeySet extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -685,17 +654,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(T fromElement, T toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(T toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(T fromElement) { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
@@ -870,6 +828,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
previous = from.ordinal() - 1;
|
||||
index = from.ordinal();
|
||||
next = from.ordinal();
|
||||
if(!isSet(index)) throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
|
||||
+151
-84
@@ -30,8 +30,9 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -363,19 +364,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -421,7 +409,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||
if(tree == null) return EMPTY_KEY_VALUE;
|
||||
if(tree == null) return getDefaultMinValue();
|
||||
KEY_TYPE result = first.key;
|
||||
removeNode(first);
|
||||
return result;
|
||||
@@ -435,7 +423,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||
if(tree == null) return EMPTY_KEY_VALUE;
|
||||
if(tree == null) return getDefaultMaxValue();
|
||||
KEY_TYPE result = last.key;
|
||||
removeNode(last);
|
||||
return result;
|
||||
@@ -695,7 +683,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@@ -1035,6 +1023,33 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public CLASS_TYPE lower(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE floor(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE higher(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE ceiling(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
@@ -1067,14 +1082,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@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(KEY_TYPE fromElement) {
|
||||
@@ -1468,7 +1475,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@@ -1482,8 +1489,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
|
||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
||||
|
||||
@@ -1543,18 +1550,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
protected Node KEY_VALUE_GENERIC_TYPE absHighFence() { return (toEnd ? null : (hiInclusive ? map.findHigherNode(hi) : map.findCeilingNode(hi))); }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE absLowFence() { return (fromStart ? null : (loInclusive ? map.findLowerNode(lo) : map.findFloorNode(lo))); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
||||
|
||||
@@ -1566,7 +1561,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
map.removeNode(entry);
|
||||
return result;
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1577,19 +1572,21 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
map.removeNode(entry);
|
||||
return result;
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
||||
if(entry == null) throw new NoSuchElementException();
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
||||
if(entry == null) throw new NoSuchElementException();
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1665,7 +1662,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
||||
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
|
||||
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@@ -1811,7 +1808,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
if (!inRange(key)) return false;
|
||||
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
||||
if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) {
|
||||
if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) {
|
||||
map.removeNode(node);
|
||||
return true;
|
||||
}
|
||||
@@ -2056,26 +2053,36 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry();
|
||||
return previousEntry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry();
|
||||
return nextEntry();
|
||||
}
|
||||
}
|
||||
|
||||
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2094,26 +2101,36 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().key;
|
||||
return previousEntry().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().key;
|
||||
return nextEntry().key;
|
||||
}
|
||||
}
|
||||
|
||||
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2132,7 +2149,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2151,39 +2168,60 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().value;
|
||||
return previousEntry().value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().value;
|
||||
return nextEntry().value;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SubMapEntryIterator
|
||||
{
|
||||
final boolean isForward;
|
||||
boolean wasForward;
|
||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||
Node KEY_VALUE_GENERIC_TYPE next;
|
||||
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
KEY_TYPE forwardFence;
|
||||
KEY_TYPE backwardFence;
|
||||
|
||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence, boolean isForward) {
|
||||
next = first;
|
||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
||||
previous = first == null ? null : movePrevious(first);
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
unboundBackwardFence = backwardFence == null;
|
||||
this.isForward = isForward;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -2192,26 +2230,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.next();
|
||||
wasForward = true;
|
||||
next = moveNext(next);
|
||||
wasForward = isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||
lastReturned = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.previous();
|
||||
wasForward = false;
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||
previous = movePrevious(previous);
|
||||
wasForward = !isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(next == lastReturned) next = moveNext(next);
|
||||
if(previous == lastReturned) previous = movePrevious(previous);
|
||||
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
map.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -2525,19 +2567,29 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().key;
|
||||
return previousEntry().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().key;
|
||||
return nextEntry().key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2545,7 +2597,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
{
|
||||
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||
{
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2564,7 +2616,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2583,7 +2635,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2601,13 +2653,24 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
abstract class MapEntryIterator
|
||||
{
|
||||
final boolean isForward;
|
||||
boolean wasMoved = false;
|
||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||
Node KEY_VALUE_GENERIC_TYPE next;
|
||||
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||
|
||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||
{
|
||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, boolean isForward) {
|
||||
next = first;
|
||||
previous = first == null ? null : movePrevious(first);
|
||||
this.isForward = isForward;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -2616,26 +2679,30 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.next();
|
||||
wasMoved = true;
|
||||
next = moveNext(next);
|
||||
wasMoved = isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||
lastReturned = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.previous();
|
||||
wasMoved = false;
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||
previous = movePrevious(previous);
|
||||
wasMoved = !isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(next == lastReturned) next = moveNext(next);
|
||||
if(previous == lastReturned) previous = movePrevious(previous);
|
||||
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
|
||||
+161
-85
@@ -30,8 +30,9 @@ import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
@@ -366,19 +367,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
@@ -424,7 +412,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||
if(tree == null) return EMPTY_KEY_VALUE;
|
||||
if(tree == null) return getDefaultMinValue();
|
||||
KEY_TYPE result = first.key;
|
||||
removeNode(first);
|
||||
return result;
|
||||
@@ -438,7 +426,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||
if(tree == null) return EMPTY_KEY_VALUE;
|
||||
if(tree == null) return getDefaultMaxValue();
|
||||
KEY_TYPE result = last.key;
|
||||
removeNode(last);
|
||||
return result;
|
||||
@@ -698,7 +686,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() {
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@@ -1093,6 +1081,33 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public CLASS_TYPE lower(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE floor(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE higher(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CLASS_TYPE ceiling(CLASS_TYPE e) {
|
||||
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
|
||||
return node != null ? node.getKey() : null;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
@@ -1125,15 +1140,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@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(KEY_TYPE fromElement) {
|
||||
if(map instanceof RB_TREE_MAP) return ((RB_TREE_MAP KEY_VALUE_GENERIC_TYPE)map).keyIterator(fromElement);
|
||||
@@ -1305,6 +1311,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
||||
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
||||
@@ -1391,6 +1402,11 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return keySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(KEY_TYPE fromKey, boolean fromInclusive, KEY_TYPE toKey, boolean toInclusive) {
|
||||
if (!inRange(fromKey, fromInclusive)) throw new IllegalArgumentException("fromKey out of range");
|
||||
@@ -1526,7 +1542,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() {
|
||||
return navigableKeySet();
|
||||
}
|
||||
|
||||
@@ -1540,8 +1556,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
|
||||
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
|
||||
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
|
||||
|
||||
@@ -1601,18 +1617,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
protected Node KEY_VALUE_GENERIC_TYPE absHighFence() { return (toEnd ? null : (hiInclusive ? map.findHigherNode(hi) : map.findCeilingNode(hi))); }
|
||||
protected Node KEY_VALUE_GENERIC_TYPE absLowFence() { return (fromStart ? null : (loInclusive ? map.findLowerNode(lo) : map.findFloorNode(lo))); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return map.comparator(); }
|
||||
|
||||
@@ -1624,7 +1628,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
map.removeNode(entry);
|
||||
return result;
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return getDefaultMinValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1635,19 +1639,21 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
map.removeNode(entry);
|
||||
return result;
|
||||
}
|
||||
return EMPTY_KEY_VALUE;
|
||||
return getDefaultMaxValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() {
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = subLowest();
|
||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
||||
if(entry == null) throw new NoSuchElementException();
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() {
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = subHighest();
|
||||
return entry == null ? map.getDefaultReturnValue() : entry.value;
|
||||
if(entry == null) throw new NoSuchElementException();
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1723,7 +1729,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
||||
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
|
||||
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@@ -1869,7 +1875,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
KEY_TYPE key = entry.ENTRY_KEY();
|
||||
if (!inRange(key)) return false;
|
||||
Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key);
|
||||
if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) {
|
||||
if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) {
|
||||
map.removeNode(node);
|
||||
return true;
|
||||
}
|
||||
@@ -2114,26 +2120,36 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class DecsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
public DecsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE previous() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry();
|
||||
return previousEntry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry();
|
||||
return nextEntry();
|
||||
}
|
||||
}
|
||||
|
||||
class AcsendingSubEntryIterator extends SubMapEntryIterator implements ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
public AcsendingSubEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2152,26 +2168,36 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class DecsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public DecsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().key;
|
||||
return previousEntry().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().key;
|
||||
return nextEntry().key;
|
||||
}
|
||||
}
|
||||
|
||||
class AcsendingSubKeyIterator extends SubMapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public AcsendingSubKeyIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2190,7 +2216,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class AcsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public AcsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2209,39 +2235,60 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class DecsendingSubValueIterator extends SubMapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public DecsendingSubValueIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence) {
|
||||
super(first, forwardFence, backwardFence);
|
||||
super(first, forwardFence, backwardFence, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().value;
|
||||
return previousEntry().value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().value;
|
||||
return nextEntry().value;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SubMapEntryIterator
|
||||
{
|
||||
final boolean isForward;
|
||||
boolean wasForward;
|
||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||
Node KEY_VALUE_GENERIC_TYPE next;
|
||||
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
KEY_TYPE forwardFence;
|
||||
KEY_TYPE backwardFence;
|
||||
|
||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence, boolean isForward) {
|
||||
next = first;
|
||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
||||
previous = first == null ? null : movePrevious(first);
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
unboundBackwardFence = backwardFence == null;
|
||||
this.isForward = isForward;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -2250,26 +2297,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.next();
|
||||
wasForward = true;
|
||||
next = moveNext(next);
|
||||
wasForward = isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||
lastReturned = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.previous();
|
||||
wasForward = false;
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||
previous = movePrevious(previous);
|
||||
wasForward = !isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(next == lastReturned) next = moveNext(next);
|
||||
if(previous == lastReturned) previous = movePrevious(previous);
|
||||
if(wasForward && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
map.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -2583,19 +2634,29 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class DescendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public DescendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
return nextEntry().key;
|
||||
return previousEntry().key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return previousEntry().key;
|
||||
return nextEntry().key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2603,7 +2664,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
{
|
||||
public AscendingMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||
{
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2622,7 +2683,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class AscendingValueIterator extends MapEntryIterator implements VALUE_BI_ITERATOR VALUE_GENERIC_TYPE
|
||||
{
|
||||
public AscendingValueIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2641,7 +2702,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
class AscendingKeyIterator extends MapEntryIterator implements BI_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
public AscendingKeyIterator(Node KEY_VALUE_GENERIC_TYPE first) {
|
||||
super(first);
|
||||
super(first, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2659,13 +2720,24 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
abstract class MapEntryIterator
|
||||
{
|
||||
final boolean isForward;
|
||||
boolean wasMoved = false;
|
||||
Node KEY_VALUE_GENERIC_TYPE lastReturned;
|
||||
Node KEY_VALUE_GENERIC_TYPE next;
|
||||
Node KEY_VALUE_GENERIC_TYPE previous;
|
||||
|
||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first)
|
||||
{
|
||||
public MapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, boolean isForward) {
|
||||
next = first;
|
||||
previous = first == null ? null : movePrevious(first);
|
||||
this.isForward = isForward;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE moveNext(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.next();
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE movePrevious(Node KEY_VALUE_GENERIC_TYPE node) {
|
||||
return node.previous();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
@@ -2674,26 +2746,30 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE nextEntry() {
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.next();
|
||||
wasMoved = true;
|
||||
next = moveNext(next);
|
||||
wasMoved = isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
protected Node KEY_VALUE_GENERIC_TYPE previousEntry() {
|
||||
lastReturned = next;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = next;
|
||||
next = next.previous();
|
||||
wasMoved = false;
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
Node KEY_VALUE_GENERIC_TYPE result = previous;
|
||||
previous = movePrevious(previous);
|
||||
wasMoved = !isForward;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(next == lastReturned) next = moveNext(next);
|
||||
if(previous == lastReturned) previous = movePrevious(previous);
|
||||
if(wasMoved && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A type specific ConcurrentMap interface that reduces boxing/unboxing.
|
||||
* Since the interface adds nothing new. It is there just for completion sake.
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public interface CONCURRENT_MAP KEY_VALUE_GENERIC_TYPE extends ConcurrentMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE compute(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.compute(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfAbsent(CLASS_TYPE key, Function<? super CLASS_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE computeIfPresent(CLASS_TYPE key, BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.computeIfPresent(key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default void forEach(BiConsumer<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE> action) {
|
||||
MAP.super.forEach(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE merge(CLASS_TYPE key, CLASS_VALUE_TYPE value, BiFunction<? super CLASS_VALUE_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
return MAP.super.merge(key, value, mappingFunction);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT && VALUE_OBJECT
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
@Override
|
||||
public boolean remove(Object key, Object value);
|
||||
@Override
|
||||
public boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue);
|
||||
@Override
|
||||
public CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value);
|
||||
|
||||
#else
|
||||
@Primitive
|
||||
@Override
|
||||
public default CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
|
||||
return MAP.super.getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public default CLASS_VALUE_TYPE putIfAbsent(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object key, Object value) {
|
||||
return MAP.super.remove(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean replace(CLASS_TYPE key, CLASS_VALUE_TYPE oldValue, CLASS_VALUE_TYPE newValue) {
|
||||
return MAP.super.replace(key, oldValue, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE replace(CLASS_TYPE key, CLASS_VALUE_TYPE value) {
|
||||
return MAP.super.replace(key, value);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public default void replaceAll(BiFunction<? super CLASS_TYPE, ? super CLASS_VALUE_TYPE, ? extends CLASS_VALUE_TYPE> mappingFunction) {
|
||||
MAP.super.replaceAll(mappingFunction);
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -31,6 +31,7 @@ import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP;
|
||||
@@ -556,8 +557,8 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
*/
|
||||
public KEY_TYPE ENTRY_KEY();
|
||||
public default CLASS_TYPE getKey() { return KEY_TO_OBJ(ENTRY_KEY()); }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if !VALUE_OBJECT
|
||||
/**
|
||||
* Type Specific getValue method that reduces boxing/unboxing
|
||||
@@ -1380,6 +1381,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @param initialSize the requested start capacity
|
||||
*/
|
||||
public BuilderCache(int initialSize) {
|
||||
if(initialSize < 0) throw new IllegalStateException("Minimum Capacity is negative. This is not allowed");
|
||||
keys = NEW_KEY_ARRAY(initialSize);
|
||||
values = NEW_VALUE_ARRAY(initialSize);
|
||||
}
|
||||
@@ -1508,6 +1510,14 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
return putElements(new LINKED_CUSTOM_HASH_MAPKV_BRACES(size, strategy));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Keys and Values into a Concurrent Hash Map
|
||||
* @return a CONCURRENT_HASH_MAP
|
||||
*/
|
||||
public CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE concurrentMap() {
|
||||
return putElements(new CONCURRENT_HASH_MAPKV_BRACES(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Keys and Values into a Array Map
|
||||
* @return a ARRAY_MAP
|
||||
|
||||
+3
-1
@@ -34,7 +34,9 @@ public interface NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE extends SORTED_MAP KEY_VAL
|
||||
/** @return a Type Specific pollLastEntry */
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||
|
||||
/** @return a Type Specific Navigable Key Set */
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet();
|
||||
/**
|
||||
* Creates a Wrapped NavigableMap that is Synchronized
|
||||
* @return a new NavigableMap that is synchronized
|
||||
|
||||
+28
@@ -1,6 +1,11 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
/**
|
||||
* A Special Map Interface giving Access to some really usefull functions
|
||||
* The Idea behind this interface is to allow access to functions that give control to the Order of elements.
|
||||
@@ -92,12 +97,17 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
* @return a new SortedMap that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize() { return MAPS.synchronize(this); }
|
||||
|
||||
/**
|
||||
@@ -106,6 +116,7 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
* @return a new SortedMap Wrapper that is synchronized
|
||||
* @see MAPS#synchronize
|
||||
*/
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE synchronize(Object mutex) { return MAPS.synchronize(this, mutex); }
|
||||
|
||||
/**
|
||||
@@ -113,5 +124,22 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
* @return a new SortedMap Wrapper that is unmodifiable
|
||||
* @see MAPS#unmodifiable
|
||||
*/
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
/**
|
||||
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
interface FastOrderedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||
/**
|
||||
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||
* @param fromElement that is going to be started from.
|
||||
* @return a improved iterator that starts from the desired element
|
||||
*/
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||
}
|
||||
}
|
||||
+13
-63
@@ -9,9 +9,11 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.ObjectSortedSet;
|
||||
#endif
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
|
||||
/**
|
||||
@@ -22,65 +24,8 @@ import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
* @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>, ORDERED_MAP KEY_VALUE_GENERIC_TYPE
|
||||
public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE, CLASS_VALUE_TYPE>, MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
/**
|
||||
* A customized put method that allows you to insert into the first index.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#putAndMoveToFirst instead (removed in 0.6.0)
|
||||
*/
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||
/**
|
||||
* A customized put method that allows you to insert into the last index. (This may be nessesary depending on the implementation)
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#putAndMoveToLast instead (removed in 0.6.0)
|
||||
*/
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A specific move method to move a given key/value to the first index.
|
||||
* @param key that should be moved to the first index
|
||||
* @return true if the value was moved.
|
||||
* @note returns false if the value was not present in the first place
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#moveToFirst instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean moveToFirst(KEY_TYPE key);
|
||||
/**
|
||||
* A specific move method to move a given key/value to the last index.
|
||||
* @param key that should be moved to the first last
|
||||
* @return true if the value was moved.
|
||||
* @note returns false if the value was not present in the first place
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#moveToLast instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean moveToLast(KEY_TYPE key);
|
||||
|
||||
/**
|
||||
* A Specific get method that allows to move teh given key/value int the first index.
|
||||
* @param key that is searched for
|
||||
* @return the given value for the requested key or default return value
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#getAndMoveToFirst instead (removed in 0.6.0)
|
||||
*/
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key);
|
||||
/**
|
||||
* A Specific get method that allows to move teh given key/value int the last index.
|
||||
* @param key that is searched for
|
||||
* @return the given value for the requested key or default return value
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_MAP#getAndMoveToLast instead (removed in 0.6.0)
|
||||
*/
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key);
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator();
|
||||
|
||||
@@ -88,7 +33,7 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet();
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
|
||||
@@ -212,11 +157,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||
|
||||
@Override
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey) { return subMap(OBJ_TO_KEY(fromKey), OBJ_TO_KEY(toKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, CLASS_TYPE toKey);
|
||||
@Override
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey) { return headMap(OBJ_TO_KEY(toKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE headMap(CLASS_TYPE toKey);
|
||||
@Override
|
||||
public default SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey) { return tailMap(OBJ_TO_KEY(fromKey)); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(CLASS_TYPE fromKey);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -227,6 +172,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap<CLASS_TYPE,
|
||||
interface FastSortedSet KEY_VALUE_GENERIC_TYPE extends MAP.FastEntrySet KEY_VALUE_GENERIC_TYPE, ObjectSortedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator();
|
||||
/**
|
||||
* Fast iterator that recycles the given Entry object to improve speed and reduce object allocation
|
||||
* @param fromElement that is going to be started from.
|
||||
* @return a improved iterator that starts from the desired element
|
||||
*/
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator(KEY_TYPE fromElement);
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -106,10 +106,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(first != last) {
|
||||
#if TYPE_OBJECT
|
||||
Arrays.fill(array, null);
|
||||
Arrays.fill(array, null);
|
||||
#endif
|
||||
first = last = 0;
|
||||
first = last = 0;
|
||||
}
|
||||
else if(first != 0) {
|
||||
first = last = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,9 +157,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) {
|
||||
if(first == last || index < 0 || index > size()) throw new NoSuchElementException();
|
||||
if(first == last || index < 0 || index >= size()) throw new NoSuchElementException();
|
||||
index += first;
|
||||
return index > array.length ? array[index-array.length] : array[index];
|
||||
return index >= array.length ? array[index-array.length] : array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,6 +434,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
KEY_TYPE value = array[index];
|
||||
removeIndex(index);
|
||||
index = ++index % array.length;
|
||||
|
||||
+2
-1
@@ -187,7 +187,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
if(firstIndex != -1){
|
||||
int compare = comparator == null ? COMPAREABLE_TO_KEY(e, array[firstIndex]) : comparator.compare(e, array[firstIndex]);
|
||||
if(compare < 0) firstIndex = size;
|
||||
@@ -414,6 +414,7 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -207,7 +207,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
|
||||
@Override
|
||||
public void enqueue(KEY_TYPE e) {
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (array.length >> 1), SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
if(size == array.length) array = Arrays.copyOf(array, (int)Math.max(Math.min((long)array.length + (long)(array.length >> 1), (long)SanityChecks.MAX_ARRAY_SIZE), size+1));
|
||||
array[size++] = e;
|
||||
ARRAYS.shiftUp(array, size-1, comparator);
|
||||
}
|
||||
@@ -389,6 +389,7 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
+41
-48
@@ -295,18 +295,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
@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 KEY_TYPE lower(KEY_TYPE e) {
|
||||
Entry KEY_GENERIC_TYPE node = findLowerNode(e);
|
||||
@@ -900,15 +888,11 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
public KEY_TYPE getDefaultMaxValue() { return super.getDefaultMinValue(); }
|
||||
|
||||
public KEY_TYPE getDefaultMinValue() { return super.getDefaultMaxValue(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
||||
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
||||
return new DescendingSubSetBRACES(set, false, fromElement, fromInclusive, false, toElement, toInclusive);
|
||||
return new DescendingSubSetBRACES(set, false, toElement, toInclusive, false, fromElement, fromInclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -985,21 +969,15 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
||||
|
||||
@Override
|
||||
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
||||
|
||||
#else
|
||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||
|
||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@@ -1203,15 +1181,6 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return entry.key;
|
||||
}
|
||||
|
||||
@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 SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -1319,6 +1288,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
@@ -1328,6 +1298,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.previous();
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
@@ -1343,6 +1314,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
forwards = true;
|
||||
@@ -1351,15 +1323,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.previous();
|
||||
forwards = false;
|
||||
return result;
|
||||
}
|
||||
@@ -1367,6 +1340,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(previous == lastReturned) previous = previous.previous();
|
||||
if(next == lastReturned) next = next.next();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
set.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1377,6 +1352,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
@@ -1386,6 +1362,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.next();
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
@@ -1401,6 +1378,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
forwards = false;
|
||||
@@ -1409,15 +1387,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.next();
|
||||
forwards = true;
|
||||
return result;
|
||||
}
|
||||
@@ -1425,6 +1404,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(previous == lastReturned) previous = previous.next();
|
||||
if(next == lastReturned) next = next.previous();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
set.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1436,11 +1417,13 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
|
||||
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1452,6 +1435,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
forwards = true;
|
||||
@@ -1460,15 +1444,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.previous();
|
||||
forwards = false;
|
||||
return result;
|
||||
}
|
||||
@@ -1476,6 +1461,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(lastReturned == previous) previous = previous.previous();
|
||||
if(lastReturned == next) next = next.next();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1486,11 +1473,13 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
|
||||
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1502,6 +1491,7 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
forwards = false;
|
||||
@@ -1510,15 +1500,16 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.next();
|
||||
forwards = true;
|
||||
return result;
|
||||
}
|
||||
@@ -1526,6 +1517,8 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(lastReturned == previous) previous = previous.next();
|
||||
if(lastReturned == next) next = next.previous();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
|
||||
@@ -3,7 +3,6 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
@@ -21,7 +20,6 @@ import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUME
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#endif
|
||||
@@ -36,7 +34,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
* This implementation does not shrink the backing array
|
||||
* @Type(T)
|
||||
*/
|
||||
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE, ORDERED_SET KEY_GENERIC_TYPE
|
||||
public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing Array */
|
||||
protected transient KEY_TYPE[] data;
|
||||
@@ -56,6 +54,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
* @throws NegativeArraySizeException if the capacity is negative
|
||||
*/
|
||||
public ARRAY_SET(int capacity) {
|
||||
if(capacity < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||
data = NEW_KEY_ARRAY(capacity);
|
||||
}
|
||||
|
||||
@@ -170,7 +169,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
else if(index != size - 1) {
|
||||
o = data[index];
|
||||
System.arraycopy(data, index+1, data, index, size - index);
|
||||
System.arraycopy(data, index+1, data, index, size - index - 1);
|
||||
data[size-1] = o;
|
||||
}
|
||||
return false;
|
||||
@@ -510,31 +509,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
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
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
/**
|
||||
* 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
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
/**
|
||||
* 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
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
public ARRAY_SET KEY_GENERIC_TYPE copy() {
|
||||
ARRAY_SET KEY_GENERIC_TYPE set = new ARRAY_SETBRACES();
|
||||
set.data = Arrays.copyOf(data, data.length);
|
||||
@@ -542,11 +516,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
size = 0;
|
||||
@@ -587,347 +556,6 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
return a;
|
||||
}
|
||||
|
||||
// Disabled until a Proper Implementation can be thought out or it is decided that the interface is thrown out.
|
||||
// private class SubSet extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE {
|
||||
// int offset;
|
||||
// int length;
|
||||
//
|
||||
// SubSet(int offset, int length) {
|
||||
// this.offset = offset;
|
||||
// this.length = length;
|
||||
// }
|
||||
//
|
||||
// int end() { return offset+length; }
|
||||
//
|
||||
// @Override
|
||||
// public boolean add(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index == -1) {
|
||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
// if(end() != size) System.arraycopy(data, end(), data, end()+1, size-(offset+length));
|
||||
// data[end()] = o;
|
||||
// size++;
|
||||
// length++;
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index == -1) {
|
||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
// System.arraycopy(data, offset, data, offset+1, size-offset);
|
||||
// data[offset] = o;
|
||||
// size++;
|
||||
// length++;
|
||||
// return true;
|
||||
// }
|
||||
// else if(index != 0) {
|
||||
// o = data[index];
|
||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
||||
// data[offset] = o;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index == -1) {
|
||||
// if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
|
||||
// System.arraycopy(data, end()+1, data, end(), size-end());
|
||||
// data[end()] = o;
|
||||
// size++;
|
||||
// length++;
|
||||
// return true;
|
||||
// }
|
||||
// else if(index != 0) {
|
||||
// o = data[index];
|
||||
// System.arraycopy(data, offset+1, data, offset, index-offset);
|
||||
// data[offset+length] = o;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean moveToFirst(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index > offset) {
|
||||
// o = data[index];
|
||||
// System.arraycopy(data, offset, data, offset+1, index-offset);
|
||||
// data[offset] = o;
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean moveToLast(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index != -1 && index < end()-1) {
|
||||
// o = data[index];
|
||||
// System.arraycopy(data, index+1, data, index, end()-index-1);
|
||||
// data[end()-1] = o;
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
//#if !TYPE_OBJECT
|
||||
// @Override
|
||||
// public boolean contains(KEY_TYPE e) {
|
||||
// return findIndex(e) != -1;
|
||||
// }
|
||||
//
|
||||
//#endif
|
||||
// @Override
|
||||
// public boolean contains(Object e) {
|
||||
// return findIndex(e) != -1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE FIRST_KEY() {
|
||||
// if(length == 0) throw new NoSuchElementException();
|
||||
// return data[offset];
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE LAST_KEY() {
|
||||
// if(length == 0) throw new NoSuchElementException();
|
||||
// return data[end()-1];
|
||||
// }
|
||||
//
|
||||
//#if !TYPE_OBJECT
|
||||
// @Override
|
||||
// public boolean remove(KEY_TYPE o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index != -1) {
|
||||
// size--;
|
||||
// length--;
|
||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
//#endif
|
||||
// @Override
|
||||
// public boolean remove(Object o) {
|
||||
// int index = findIndex(o);
|
||||
// if(index != -1) {
|
||||
// size--;
|
||||
// length--;
|
||||
// if(index != size) System.arraycopy(data, index+1, data, index, size - index);
|
||||
//#if TYPE_OBJECT
|
||||
// data[size] = EMPTY_KEY_VALUE;
|
||||
//#endif
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE POLL_FIRST_KEY() {
|
||||
// if(length == 0) throw new NoSuchElementException();
|
||||
// size--;
|
||||
// length--;
|
||||
// KEY_TYPE result = data[offset];
|
||||
// System.arraycopy(data, offset+1, data, offset, size-offset);
|
||||
//#if TYPE_OBJECT
|
||||
// data[size] = EMPTY_KEY_VALUE;
|
||||
//#endif
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE POLL_LAST_KEY() {
|
||||
// if(length == 0) throw new NoSuchElementException();
|
||||
// KEY_TYPE result = data[offset+length];
|
||||
// size--;
|
||||
// length--;
|
||||
// System.arraycopy(data, end()+1, data, end(), size-end());
|
||||
//#if TYPE_OBJECT
|
||||
// data[size] = EMPTY_KEY_VALUE;
|
||||
//#endif
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public COMPARATOR KEY_GENERIC_TYPE comparator() {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
// return new SetIterator(offset);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
// int index = findIndex(fromElement);
|
||||
// if(index != -1) return new SetIterator(index);
|
||||
// throw new NoSuchElementException();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public SubSet copy() { throw new UnsupportedOperationException(); }
|
||||
//
|
||||
// @Override
|
||||
// public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) {
|
||||
// int fromIndex = findIndex(fromElement);
|
||||
// int toIndex = findIndex(toElement);
|
||||
// if(fromIndex == -1 || toIndex == -1) throw new NoSuchElementException();
|
||||
// return new SubSet(fromIndex, toIndex - fromIndex + 1);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) {
|
||||
// int toIndex = findIndex(toElement);
|
||||
// if(toIndex == -1) throw new NoSuchElementException();
|
||||
// return new SubSet(0, toIndex+1);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) {
|
||||
// int fromIndex = findIndex(fromElement);
|
||||
// if(fromIndex == -1) throw new NoSuchElementException();
|
||||
// return new SubSet(fromIndex, size - fromIndex);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int size() {
|
||||
// return length;
|
||||
// }
|
||||
//
|
||||
//#if !TYPE_OBJECT
|
||||
// @Override
|
||||
// public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
// if(a == null || a.length < size()) return Arrays.copyOfRange(data, offset, end());
|
||||
// System.arraycopy(data, offset, a, 0, size());
|
||||
// return a;
|
||||
// }
|
||||
//
|
||||
//#endif
|
||||
// @Override
|
||||
// @Deprecated
|
||||
// public Object[] toArray() {
|
||||
// Object[] obj = new Object[size()];
|
||||
// for(int i = 0;i<size();i++)
|
||||
// obj[i] = KEY_TO_OBJ(data[offset+i]);
|
||||
// return obj;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Primitive
|
||||
// public <E> E[] toArray(E[] a) {
|
||||
// if(a == null) a = (E[])new Object[size()];
|
||||
// else if(a.length < size()) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size());
|
||||
// for(int i = 0;i<size();i++)
|
||||
// a[i] = (E)KEY_TO_OBJ(data[offset+i]);
|
||||
// return a;
|
||||
// }
|
||||
//
|
||||
//#if !TYPE_OBJECT
|
||||
// protected int findIndex(KEY_TYPE o) {
|
||||
// for(int i = length-1;i>=0;i--)
|
||||
// if(KEY_EQUALS(data[offset+i], o)) return i + offset;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
//#endif
|
||||
// protected int findIndex(Object o) {
|
||||
// for(int i = length-1;i>=0;i--)
|
||||
// if(EQUALS_KEY_TYPE(data[offset+i], o)) return i + offset;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
// int index;
|
||||
// int lastReturned = -1;
|
||||
//
|
||||
// public SetIterator(int index) {
|
||||
// this.index = index;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasNext() {
|
||||
// return index < size();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE NEXT() {
|
||||
// if(!hasNext()) throw new NoSuchElementException();
|
||||
// lastReturned = index;
|
||||
// return data[index++];
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasPrevious() {
|
||||
// return index > 0;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public KEY_TYPE PREVIOUS() {
|
||||
// if(!hasPrevious()) throw new NoSuchElementException();
|
||||
// lastReturned = index;
|
||||
// return data[index--];
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int nextIndex() {
|
||||
// return index;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int previousIndex() {
|
||||
// return index-1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void remove() {
|
||||
// if(lastReturned == -1)
|
||||
// throw new IllegalStateException();
|
||||
// SubSet.this.remove(data[lastReturned]);
|
||||
// if(lastReturned < index)
|
||||
// index--;
|
||||
// lastReturned = -1;
|
||||
// }
|
||||
//
|
||||
// #if TYPE_OBJECT
|
||||
// @Override
|
||||
// public void set(Object e) { throw new UnsupportedOperationException(); }
|
||||
//
|
||||
// @Override
|
||||
// public void add(Object e) { throw new UnsupportedOperationException(); }
|
||||
//
|
||||
// #else
|
||||
// @Override
|
||||
// public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
//
|
||||
// @Override
|
||||
// public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
//
|
||||
// #endif
|
||||
// @Override
|
||||
// public int skip(int amount) {
|
||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
// int steps = Math.min(amount, (size() - 1) - index);
|
||||
// index += steps;
|
||||
// return steps;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int back(int amount) {
|
||||
// if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
// int steps = Math.min(amount, index);
|
||||
// index -= steps;
|
||||
// return steps;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
@@ -956,8 +584,8 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return data[index--];
|
||||
--index;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -996,8 +624,9 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, (size() - 1) - index);
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@@ -1006,6 +635,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-19
@@ -1,7 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
@@ -15,7 +14,6 @@ import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
@@ -34,7 +32,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* Extra to that there is a couple quality of life functions provided
|
||||
* @Type(T)
|
||||
*/
|
||||
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements SORTED_SET KEY_GENERIC_TYPE
|
||||
public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing keys array */
|
||||
protected transient KEY_TYPE[] keys;
|
||||
@@ -459,18 +457,6 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -516,6 +502,30 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
@@ -544,9 +554,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -554,9 +563,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = next;
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
+35
-29
@@ -1,7 +1,6 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
@@ -16,9 +15,6 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@@ -37,7 +33,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||
* @Type(T)
|
||||
*/
|
||||
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
|
||||
public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected transient long[] links;
|
||||
@@ -127,7 +123,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||
*/
|
||||
public LINKED_CUSTOM_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor, STRATEGY KEY_SUPER_GENERIC_TYPE strategy) {
|
||||
this(length < 0 ? 0 : length, strategy);
|
||||
this(length, strategy);
|
||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
@@ -241,6 +237,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
|
||||
@@ -253,6 +250,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return true;
|
||||
@@ -286,7 +284,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -308,7 +306,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -374,8 +372,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
@@ -397,8 +394,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
lastIndex = (int)(links[pos] >>> 32);
|
||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(strategy.equals(result, EMPTY_KEY_VALUE)) {
|
||||
@@ -512,7 +508,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -672,18 +668,6 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
@@ -731,6 +715,30 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
@@ -789,9 +797,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -799,9 +806,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = next;
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
+35
-29
@@ -1,8 +1,5 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -19,7 +16,6 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
@@ -38,7 +34,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* This implementation of SortedSet does not support SubSet of any kind. It implements the interface due to sortability and first/last access
|
||||
* @Type(T)
|
||||
*/
|
||||
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
|
||||
public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
/** The Backing array for links between nodes. Left 32 Bits => Previous Entry, Right 32 Bits => Next Entry */
|
||||
protected transient long[] links;
|
||||
@@ -114,7 +110,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
* @throws IllegalStateException if offset and length causes to step outside of the arrays range
|
||||
*/
|
||||
public LINKED_HASH_SET(KEY_TYPE[] array, int offset, int length, float loadFactor) {
|
||||
this(length < 0 ? 0 : length);
|
||||
this(length);
|
||||
SanityChecks.checkArrayCapacity(array.length, offset, length);
|
||||
for(int i = 0;i<length;i++) add(array[offset+i]);
|
||||
}
|
||||
@@ -212,6 +208,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
|
||||
@@ -224,6 +221,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
keys[pos] = o;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return true;
|
||||
@@ -257,7 +255,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@@ -279,7 +277,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@@ -345,8 +343,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
@@ -368,8 +365,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
lastIndex = (int)(links[pos] >>> 32);
|
||||
if(0 <= lastIndex) links[lastIndex] |= 0xFFFFFFFFL;
|
||||
onNodeRemoved(pos);
|
||||
KEY_TYPE result = keys[pos];
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result)) {
|
||||
@@ -603,7 +599,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -643,18 +639,6 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return null; }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE headSet(KEY_TYPE toElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE tailSet(KEY_TYPE fromElement) { throw new UnsupportedOperationException(); }
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
@@ -692,6 +676,30 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != -1;
|
||||
@@ -760,9 +768,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
current = previous;
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@@ -770,9 +777,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
current = next;
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
+5
-5
@@ -373,10 +373,10 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
#endif
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int newSize = HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor));
|
||||
if(newSize >= nullIndex || size >= Math.min((int)Math.ceil(newSize * loadFactor), newSize - 1)) return false;
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
try {
|
||||
rehash(newSize);
|
||||
rehash(request);
|
||||
}
|
||||
catch(OutOfMemoryError e) { return false; }
|
||||
return true;
|
||||
@@ -385,7 +385,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -589,7 +589,7 @@ public class CUSTOM_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_T
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
|
||||
+5
-5
@@ -340,10 +340,10 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
#endif
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
int newSize = HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor));
|
||||
if(newSize >= nullIndex || size >= Math.min((int)Math.ceil(newSize * loadFactor), newSize - 1)) return false;
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= nullIndex || this.size >= Math.min((int)Math.ceil(request * loadFactor), request - 1)) return false;
|
||||
try {
|
||||
rehash(newSize);
|
||||
rehash(request);
|
||||
}
|
||||
catch(OutOfMemoryError e) { return false; }
|
||||
return true;
|
||||
@@ -352,7 +352,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
int request = Math.max(minCapacity, HashUtil.nextPowerOfTwo((int)Math.ceil(size / loadFactor)));
|
||||
if(request >= size) {
|
||||
if(request >= nullIndex) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
@@ -452,7 +452,7 @@ public class HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE imp
|
||||
state = keys[nullIndex];
|
||||
empty = false;
|
||||
}
|
||||
for(int i = 0;i<size;i++) {
|
||||
for(int i = nullIndex-1;i>=0;i--) {
|
||||
if(KEY_EQUALS_NULL(keys[i])) continue;
|
||||
if(empty) {
|
||||
empty = false;
|
||||
|
||||
+41
-48
@@ -295,18 +295,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
#endif
|
||||
@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 KEY_TYPE lower(KEY_TYPE e) {
|
||||
Entry KEY_GENERIC_TYPE node = findLowerNode(e);
|
||||
@@ -961,15 +949,11 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return comparator; }
|
||||
|
||||
public KEY_TYPE getDefaultMaxValue() { return super.getDefaultMinValue(); }
|
||||
|
||||
public KEY_TYPE getDefaultMinValue() { return super.getDefaultMaxValue(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) {
|
||||
if(!inRange(fromElement, fromInclusive)) throw new IllegalArgumentException("fromElement out of range");
|
||||
if(!inRange(toElement, toInclusive)) throw new IllegalArgumentException("toElement out of range");
|
||||
return new DescendingSubSetBRACES(set, false, fromElement, fromInclusive, false, toElement, toInclusive);
|
||||
return new DescendingSubSetBRACES(set, false, toElement, toInclusive, false, fromElement, fromInclusive);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1046,21 +1030,15 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE value) { set.setDefaultMaxValue(value); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMaxValue() { return set.getDefaultMaxValue(); }
|
||||
|
||||
@Override
|
||||
public void setDefaultMinValue(KEY_TYPE value) { set.setDefaultMinValue(value); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMinValue() { return set.getDefaultMinValue(); }
|
||||
|
||||
#else
|
||||
public KEY_TYPE getDefaultMaxValue() { return null; }
|
||||
|
||||
public KEY_TYPE getDefaultMinValue() { return null; }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
@@ -1264,15 +1242,6 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
return entry.key;
|
||||
}
|
||||
|
||||
@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 SubSet KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -1380,6 +1349,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
@@ -1389,6 +1359,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public AscendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.previous();
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
@@ -1404,6 +1375,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
forwards = true;
|
||||
@@ -1412,15 +1384,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.previous();
|
||||
forwards = false;
|
||||
return result;
|
||||
}
|
||||
@@ -1428,6 +1401,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(previous == lastReturned) previous = previous.previous();
|
||||
if(next == lastReturned) next = next.next();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
set.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1438,6 +1413,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
boolean unboundForwardFence;
|
||||
boolean unboundBackwardFence;
|
||||
@@ -1447,6 +1423,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public DescendingSubSetIterator(Entry KEY_GENERIC_TYPE first, Entry KEY_GENERIC_TYPE forwardFence, Entry KEY_GENERIC_TYPE backwardFence)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.next();
|
||||
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||
unboundForwardFence = forwardFence == null;
|
||||
@@ -1462,6 +1439,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
forwards = false;
|
||||
@@ -1470,15 +1448,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null && (unboundBackwardFence || next.key != backwardFence);
|
||||
return previous != null && (unboundBackwardFence || previous.key != backwardFence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.next();
|
||||
forwards = true;
|
||||
return result;
|
||||
}
|
||||
@@ -1486,6 +1465,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(previous == lastReturned) previous = previous.next();
|
||||
if(next == lastReturned) next = next.previous();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
set.removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1497,11 +1478,13 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
|
||||
public AscendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.previous();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1513,6 +1496,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
forwards = true;
|
||||
@@ -1521,15 +1505,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.previous();
|
||||
forwards = false;
|
||||
return result;
|
||||
}
|
||||
@@ -1537,6 +1522,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(lastReturned == previous) previous = previous.previous();
|
||||
if(lastReturned == next) next = next.next();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
@@ -1547,11 +1534,13 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
{
|
||||
Entry KEY_GENERIC_TYPE lastReturned;
|
||||
Entry KEY_GENERIC_TYPE next;
|
||||
Entry KEY_GENERIC_TYPE previous;
|
||||
boolean forwards = false;
|
||||
|
||||
public DescendingSetIterator(Entry KEY_GENERIC_TYPE first)
|
||||
{
|
||||
next = first;
|
||||
previous = first == null ? null : first.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1563,6 +1552,7 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
previous = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.previous();
|
||||
forwards = false;
|
||||
@@ -1571,15 +1561,16 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return next != null;
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
lastReturned = next;
|
||||
KEY_TYPE result = next.key;
|
||||
next = next.next();
|
||||
lastReturned = previous;
|
||||
next = previous;
|
||||
KEY_TYPE result = previous.key;
|
||||
previous = previous.next();
|
||||
forwards = true;
|
||||
return result;
|
||||
}
|
||||
@@ -1587,6 +1578,8 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == null) throw new IllegalStateException();
|
||||
if(lastReturned == previous) previous = previous.next();
|
||||
if(lastReturned == next) next = next.previous();
|
||||
if(forwards && lastReturned.needsSuccessor()) next = lastReturned;
|
||||
removeNode(lastReturned);
|
||||
lastReturned = null;
|
||||
|
||||
@@ -19,47 +19,8 @@ import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
* @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 ORDERED_SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
||||
public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SortedSet<CLASS_TYPE>
|
||||
{
|
||||
|
||||
/**
|
||||
* A customized add method that allows you to insert into the first index.
|
||||
* @param o the element that should be inserted
|
||||
* @return true if it was added
|
||||
* @see java.util.Set#add(Object)
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_SET#addAndMoveToFirst instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o);
|
||||
/**
|
||||
* A customized add method that allows you to insert into the last index.
|
||||
* @param o the element that should be inserted
|
||||
* @return true if it was added
|
||||
* @see java.util.Set#add(Object)
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_SET#addAndMoveToLast instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean addAndMoveToLast(KEY_TYPE o);
|
||||
|
||||
/**
|
||||
* A specific move method to move a given key to the first index.
|
||||
* @param o that should be moved to the first index
|
||||
* @return true if the value was moved.
|
||||
* @note returns false if the value was not present in the first place
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_SET#moveToFirst instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean moveToFirst(KEY_TYPE o);
|
||||
/**
|
||||
* A specific move method to move a given key to the last index.
|
||||
* @param o that should be moved to the first last
|
||||
* @return true if the value was moved.
|
||||
* @note returns false if the value was not present in the first place
|
||||
* @note some implementations do not support this method
|
||||
* @deprecated use ORDERED_SET#moveToLast instead (removed in 0.6.0)
|
||||
*/
|
||||
public boolean moveToLast(KEY_TYPE o);
|
||||
|
||||
/**
|
||||
* A Type Specific Comparator method
|
||||
* @return the type specific comparator
|
||||
|
||||
@@ -348,9 +348,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @return input array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] stableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
stableSort(array, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,9 +388,11 @@ public class ARRAYS
|
||||
* Stable sort referres to Mergesort or Insertionsort
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void stableSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] stableSort(KEY_TYPE[] array) {
|
||||
stableSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,9 +427,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] unstableSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
unstableSort(array, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,9 +467,11 @@ public class ARRAYS
|
||||
* Unstable sort referres to QuickSort or SelectionSort
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void unstableSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] unstableSort(KEY_TYPE[] array) {
|
||||
unstableSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -496,9 +504,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] insertionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
insertionSort(array, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -535,9 +545,11 @@ public class ARRAYS
|
||||
* Sorts an array according to the natural ascending order using InsertionSort,
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void insertionSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] insertionSort(KEY_TYPE[] array) {
|
||||
insertionSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -573,9 +585,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] selectionSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
selectionSort(array, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -617,9 +631,11 @@ public class ARRAYS
|
||||
* Sorts an array according to the natural ascending order using Selection Sort,
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void selectionSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] selectionSort(KEY_TYPE[] array) {
|
||||
selectionSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -661,9 +677,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] mergeSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
mergeSort(array, null, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -713,9 +731,11 @@ public class ARRAYS
|
||||
* This implementation was copied from <a href="https://github.com/vigna/fastutil">FastUtil</a> with a couple custom optimizations
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void mergeSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] mergeSort(KEY_TYPE[] array) {
|
||||
mergeSort(array, null, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -922,9 +942,11 @@ public class ARRAYS
|
||||
* @author Speiger
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void memFreeMergeSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] memFreeMergeSort(KEY_TYPE[] array) {
|
||||
memFreeMergeSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1099,9 +1121,11 @@ public class ARRAYS
|
||||
* @param array the array that needs to be sorted
|
||||
* @param comp the Comparator that decides the sorting order
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] quickSort(KEY_TYPE[] array, COMPARATOR KEY_GENERIC_TYPE comp) {
|
||||
quickSort(array, 0, array.length, comp);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1157,9 +1181,11 @@ public class ARRAYS
|
||||
* and that sorting Algorithm is based on the tuned quicksort adapted from Jon L. Bentley and M. DouglasMcIlroy, "Engineering a Sort Function", Software: Practice and Experience, 23(11), pages1249−1265, 1993.
|
||||
* @param array the array that needs to be sorted
|
||||
* @ArrayType(T)
|
||||
* @return input array
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES void quickSort(KEY_TYPE[] array) {
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] quickSort(KEY_TYPE[] array) {
|
||||
quickSort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+43
-12
@@ -7,15 +7,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
@@ -71,15 +69,15 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* The Task Object is also pause-able/Interruptable at any moment during the Processing. <br>
|
||||
*
|
||||
* A small example
|
||||
* <pre>
|
||||
* public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||
* <pre><code>
|
||||
* public void processFiles(ObjectCollection<String> potentialFiles) {
|
||||
* potentialFiles.asAsync()
|
||||
* .map(Paths::get).filter(Files::exists) //Modifies the collection (Optional)
|
||||
* .forEach(Files::delete) //Creates the action (Required)
|
||||
* .callback(T -> {}} //Callback on completion (Optional)
|
||||
* .onCompletion(T -> {}} //Callback on completion (Optional)
|
||||
* .execute() //Starts the task. (Required)
|
||||
* }
|
||||
* </pre>
|
||||
* </code></pre>
|
||||
* @author Speiger
|
||||
*
|
||||
* @Type(T)
|
||||
@@ -91,7 +89,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
|
||||
/**
|
||||
* Main Constructor that uses a Iterable to build a Offthread Task.
|
||||
* @param iterable
|
||||
* @param iterable that should be processed
|
||||
*/
|
||||
public ASYNC_BUILDER(ITERABLE KEY_GENERIC_TYPE iterable) {
|
||||
this.iterable = iterable;
|
||||
@@ -99,12 +97,32 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
|
||||
/**
|
||||
* Helper constructor.
|
||||
* @param task
|
||||
* @param task that had been build
|
||||
*/
|
||||
public ASYNC_BUILDER(BASE_TASK KEY_GENERIC_TYPE task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that automatically wraps a Iterable into a AsyncBuilder since it forces this collections Iterable.
|
||||
* @param iterable that should be wrapped
|
||||
* @Type(T)
|
||||
* @return a AsyncBuilder with the iterable wrapped
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ASYNC_BUILDER KEY_GENERIC_TYPE of(Iterable<CLASS_TYPE> iterable) {
|
||||
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.
|
||||
* @param values that should be wrapped
|
||||
* @Type(T)
|
||||
* @return a AsyncBuilder with the values wrapped
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ASYNC_BUILDER KEY_GENERIC_TYPE of(KEY_TYPE...values) {
|
||||
return new ASYNC_BUILDERBRACES(ARRAY_LIST.wrap(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the elements to something else
|
||||
* @param mapper the mapping function
|
||||
@@ -165,6 +183,17 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the elements inside of the Iterable.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it, and this will affect the pausing feature.
|
||||
* @param sorter that sorts the elements.
|
||||
* @return self with a sorter applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
iterable = ITERABLES.sorted(iterable, sorter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to preview elements before they are processed
|
||||
* @param action the action that should be applied
|
||||
@@ -298,8 +327,9 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
* Can only be set after the action was decided on.
|
||||
* @param executor that executes the task, defaults to {@link SanityChecks#invokeAsyncTask(Runnable) }
|
||||
* @return self with the executor set
|
||||
* @note has to be NonNull
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE executor(@Nonnull Executor executor) {
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE executor(Executor executor) {
|
||||
if(task == null) throw new IllegalStateException("Action is missing");
|
||||
task.withExecutor(executor);
|
||||
return this;
|
||||
@@ -310,8 +340,9 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
* The state of the task has to be validated by the callback.
|
||||
* @param callback that should be notified after completion of the task
|
||||
* @return self with the callback set
|
||||
* @note can be null
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE callback(@Nullable Consumer<TASK KEY_GENERIC_TYPE> callback) {
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE onCompletion(Consumer<TASK KEY_GENERIC_TYPE> callback) {
|
||||
if(task == null) throw new IllegalStateException("Action is missing");
|
||||
task.withCallback(callback);
|
||||
return this;
|
||||
|
||||
+24
-7
@@ -186,7 +186,10 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public int hashCode() { synchronized(mutex) { return c.hashCode(); } }
|
||||
@Override
|
||||
public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } }
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == this) return true;
|
||||
synchronized(mutex) { return c.equals(obj); }
|
||||
}
|
||||
@Override
|
||||
public String toString() { synchronized(mutex) { return c.toString(); } }
|
||||
@Override
|
||||
@@ -308,7 +311,7 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public int hashCode() { return c.hashCode(); }
|
||||
@Override
|
||||
public boolean equals(Object obj) { return c.equals(obj); }
|
||||
public boolean equals(Object obj) { return obj == this || c.equals(obj); }
|
||||
@Override
|
||||
public String toString() { return c.toString(); }
|
||||
@Override
|
||||
@@ -350,7 +353,7 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { return false; }
|
||||
@Override
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
||||
public boolean containsAll(COLLECTION KEY_GENERIC_TYPE c) { return c.isEmpty(); }
|
||||
@Override
|
||||
public boolean containsAny(COLLECTION KEY_GENERIC_TYPE c) { return false; }
|
||||
#else
|
||||
@@ -362,7 +365,7 @@ public class COLLECTIONS
|
||||
public boolean containsAny(Collection<?> c) { return false; }
|
||||
@Override
|
||||
@Primitive
|
||||
public boolean containsAll(Collection<?> c) { return false; }
|
||||
public boolean containsAll(Collection<?> c) { return c.isEmpty(); }
|
||||
@Override
|
||||
public int hashCode() { return 0; }
|
||||
|
||||
@@ -401,14 +404,28 @@ public class COLLECTIONS
|
||||
public Object[] toArray() { return ObjectArrays.EMPTY_ARRAY; }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) { return a; }
|
||||
public <T> T[] toArray(T[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY() { return ARRAYS.EMPTY_ARRAY; }
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { return a; }
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public <E> E[] toArray(E[] a) { return a; }
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a != null && a.length > 0)
|
||||
a[0] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.empty(); }
|
||||
|
||||
@@ -3,6 +3,8 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
import java.util.Objects;
|
||||
#if TYPE_BOOLEAN
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
#else if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
@@ -12,8 +14,11 @@ import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#if !TYPE_BOOLEAN
|
||||
@@ -164,6 +169,30 @@ public class ITERABLES
|
||||
return new LimitedIterableBRACES(wrap(iterable), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterable.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterable that should be sorted
|
||||
* @param sorter that sorts the iterable. Can be null.
|
||||
* @Type(T)
|
||||
* @return a sorted iterable.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIterableBRACES(iterable, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterable from a Java Iterable
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterable that should be sorted
|
||||
* @param sorter that sorts the iterable. Can be null.
|
||||
* @Type(T)
|
||||
* @return a sorted iterable.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(Iterable<? extends CLASS_TYPE> iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIterableBRACES(wrap(iterable), sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterable.
|
||||
* @param iterable that should be peeked at
|
||||
@@ -359,6 +388,42 @@ public class ITERABLES
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
|
||||
public SortedIterable(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
this.iterable = iterable;
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.sorted(iterable.iterator(), sorter);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
|
||||
+67
-11
@@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
|
||||
@@ -11,6 +12,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -32,7 +34,7 @@ public class ITERATORS
|
||||
/**
|
||||
* Empty Iterator Reference
|
||||
*/
|
||||
public static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
||||
private static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
||||
|
||||
/**
|
||||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||
@@ -235,6 +237,30 @@ public class ITERATORS
|
||||
return new LimitedIteratorBRACES(wrap(iterator), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterator beforehand.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterator that should be sorted.
|
||||
* @param sorter the sorter of the iterator. Can be null.
|
||||
* @Type(T)
|
||||
* @return a new sorted iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIteratorBRACES(iterator, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterator beforehand from a Java Iterator.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterator that should be sorted.
|
||||
* @param sorter the sorter of the iterator. Can be null.
|
||||
* @Type(T)
|
||||
* @return a new sorted iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(Iterator<? extends CLASS_TYPE> iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIteratorBRACES(wrap(iterator), sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterator.
|
||||
* @param iterator that should be peeked at
|
||||
@@ -273,7 +299,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@@ -709,7 +735,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
return EMPTY_KEY_VALUE;
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -719,7 +745,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
return EMPTY_KEY_VALUE;
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -729,7 +755,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -761,6 +787,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return a[from++];
|
||||
}
|
||||
|
||||
@@ -828,7 +855,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
T result = last.next();
|
||||
foundNext = false;
|
||||
return result;
|
||||
@@ -864,13 +891,42 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
T result = last.next();
|
||||
foundNext = false;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SortedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
LIST KEY_GENERIC_TYPE sortedElements = null;
|
||||
int index = 0;
|
||||
|
||||
public SortedIterator(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
this.iterator = iterator;
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if(sortedElements == null) {
|
||||
boolean hasNext = iterator.hasNext();
|
||||
sortedElements = hasNext ? pour(iterator) : LISTS.empty();
|
||||
if(hasNext) sortedElements.unstableSort(sorter);
|
||||
}
|
||||
return index < sortedElements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return sortedElements.GET_KEY(index++);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DistinctIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
@@ -916,7 +972,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
foundNext = false;
|
||||
return lastFound;
|
||||
}
|
||||
@@ -953,7 +1009,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
foundNext = false;
|
||||
return lastFound;
|
||||
}
|
||||
@@ -976,7 +1032,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
limit--;
|
||||
return iterator.NEXT();
|
||||
}
|
||||
@@ -999,7 +1055,7 @@ public class ITERATORS
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
KEY_TYPE result = iterator.NEXT();
|
||||
action.accept(result);
|
||||
return result;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.RandomAccess;
|
||||
@@ -27,7 +28,7 @@ public class LISTS
|
||||
/**
|
||||
* Empty List reference
|
||||
*/
|
||||
public static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES();
|
||||
private static final EmptyList NO_GENERIC_TYPE EMPTY = new EmptyListBRACES();
|
||||
|
||||
/**
|
||||
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||
@@ -356,7 +357,7 @@ public class LISTS
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { addElements(from, a, offset, length); } }
|
||||
public void addElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { l.addElements(from, a, offset, length); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) { synchronized(mutex) { return l.getElements(from, a, offset, length); } }
|
||||
@@ -601,6 +602,16 @@ public class LISTS
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { return 1; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o == this) return true;
|
||||
if(!(o instanceof List)) return false;
|
||||
return ((List<?>)o).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) { throw new UnsupportedOperationException(); }
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
#if TYPE_BOOLEAN
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.sets.AbstractBooleanSet;
|
||||
@@ -34,7 +36,7 @@ public class SETS
|
||||
/**
|
||||
* Empty Set Variable
|
||||
*/
|
||||
public static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
||||
private static final SET NO_GENERIC_TYPE EMPTY = new EmptySetBRACES();
|
||||
|
||||
/**
|
||||
* EmptySet getter
|
||||
@@ -216,10 +218,10 @@ public class SETS
|
||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||
boolean next = true;
|
||||
@Override
|
||||
public boolean hasNext() { return next = false; }
|
||||
public boolean hasNext() { return next; }
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!next) throw new IllegalStateException();
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
next = false;
|
||||
return element;
|
||||
}
|
||||
@@ -241,6 +243,13 @@ public class SETS
|
||||
@Override
|
||||
public KEY_TYPE addOrGet(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o == this) return true;
|
||||
if(!(o instanceof Set)) return false;
|
||||
return ((Set<?>)o).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptySet KEY_GENERIC_TYPE copy() { return this; }
|
||||
}
|
||||
@@ -258,25 +267,38 @@ public class SETS
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { return n.contains(o); }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE lower(CLASS_TYPE e) { return n.lower(e); }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE floor(CLASS_TYPE e) { return n.floor(e); }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE ceiling(CLASS_TYPE e) { return n.ceiling(e); }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE higher(CLASS_TYPE e) { return n.higher(e); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object o) { return n.contains(o); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE lower(KEY_TYPE e) { return n.lower(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floor(KEY_TYPE e) { return n.floor(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { return n.ceiling(e); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { return n.higher(e); }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public CLASS_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public CLASS_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@@ -291,7 +313,7 @@ public class SETS
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE copy() { return n.copy(); }
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE subSet(KEY_TYPE fromElement, boolean fromInclusive, KEY_TYPE toElement, boolean toInclusive) { return SETS.unmodifiable(n.subSet(fromElement, fromInclusive, toElement, toInclusive)); }
|
||||
@@ -360,18 +382,6 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { return s.comparator(); }
|
||||
@Override
|
||||
@@ -466,27 +476,33 @@ public class SETS
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE o) { synchronized(mutex) { return n.contains(o); } }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE lower(CLASS_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE floor(CLASS_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE ceiling(CLASS_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public CLASS_TYPE higher(CLASS_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE lower(KEY_TYPE e) { synchronized(mutex) { return n.lower(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE floor(KEY_TYPE e) { synchronized(mutex) { return n.floor(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE ceiling(KEY_TYPE e) { synchronized(mutex) { return n.ceiling(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE higher(KEY_TYPE e) { synchronized(mutex) { return n.higher(e); } }
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void setDefaultMaxValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMaxValue(e); } }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE getDefaultMaxValue() { synchronized(mutex) { return n.getDefaultMaxValue(); } }
|
||||
|
||||
@Override
|
||||
public void setDefaultMinValue(KEY_TYPE e) { synchronized(mutex) { n.setDefaultMinValue(e); } }
|
||||
|
||||
@@ -557,18 +573,6 @@ public class SETS
|
||||
s = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToLast(o); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.moveToFirst(o); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToLast(KEY_TYPE o) { synchronized(mutex) { return s.moveToLast(o); } }
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator(){ synchronized(mutex) { return s.comparator(); } }
|
||||
@Override
|
||||
|
||||
+6
-1
@@ -1,6 +1,7 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Spliterator;
|
||||
#if PRIMITIVES
|
||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||
@@ -329,7 +330,11 @@ public class SPLIT_ITERATORS
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return array[index++]; }
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
return array[index++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() { return index < fence; }
|
||||
}
|
||||
|
||||
+157
-70
@@ -19,8 +19,11 @@ import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.sets.ObjectSet;
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.objects.utils.ObjectSets;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.consumer.BI_CONSUMER;
|
||||
@@ -34,6 +37,8 @@ import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SORTED_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
@@ -42,6 +47,7 @@ import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_COLLECTIONS;
|
||||
#if !SAME_TYPE && !VALUE_OBJECT
|
||||
import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_SETS;
|
||||
@@ -57,7 +63,21 @@ public class MAPS
|
||||
/**
|
||||
* Empty Map Variable
|
||||
*/
|
||||
public static final MAP NO_KV_GENERIC_TYPE EMPTY = new EmptyMapKV_BRACES();
|
||||
private static final MAP NO_KV_GENERIC_TYPE EMPTY = new EmptyMapKV_BRACES();
|
||||
|
||||
/**
|
||||
* Empty Map getter function that autocasts to the desired Key and Value
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
* @return empty map of desired type
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT || VALUE_OBJECT
|
||||
return (MAP KEY_VALUE_GENERIC_TYPE)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
/**
|
||||
@@ -104,19 +124,6 @@ public class MAPS
|
||||
}
|
||||
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Empty Map getter function that autocasts to the desired Key and Value
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
* @return empty map of desired type
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT || VALUE_OBJECT
|
||||
return (MAP KEY_VALUE_GENERIC_TYPE)EMPTY;
|
||||
#else
|
||||
return EMPTY;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that creates a Helper wrapper to synchronize access into the map.
|
||||
@@ -253,7 +260,7 @@ public class MAPS
|
||||
* @ValueType(V)
|
||||
* @return a Unmodifyable Entry
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { return entry instanceof UnmodifyableEntry ? entry : new UnmodifyableEntryKV_BRACES(entry); }
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { return entry instanceof UnmodifyableEntry ? entry : (entry == null ? null : new UnmodifyableEntryKV_BRACES(entry)); }
|
||||
/**
|
||||
* A Helper function that creates a Unmodifyable Entry
|
||||
* @param entry the Entry that should be made unmodifiable
|
||||
@@ -261,7 +268,7 @@ public class MAPS
|
||||
* @ValueType(V)
|
||||
* @return a Unmodifyable Entry
|
||||
*/
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) { return entry instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)entry : new UnmodifyableEntryKV_BRACES(entry); }
|
||||
public static GENERIC_KEY_VALUE_BRACES MAP.Entry KEY_VALUE_GENERIC_TYPE unmodifiable(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) { return entry instanceof UnmodifyableEntry ? (UnmodifyableEntry KEY_VALUE_GENERIC_TYPE)entry : (entry == null ? null : new UnmodifyableEntryKV_BRACES(entry)); }
|
||||
|
||||
/**
|
||||
* Creates a Singleton map from the provided values.
|
||||
@@ -315,6 +322,18 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EQUALS_KEY_TYPE(key, this.key) ? value : defaultValue; }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SingletonMap KEY_VALUE_GENERIC_TYPE copy() { return new SingletonMapKV_BRACES(key, value); }
|
||||
@Override
|
||||
@@ -363,8 +382,20 @@ public class MAPS
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return getDefaultReturnValue(); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return EMPTY_VALUE; }
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return defaultValue; }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() { return SETS.empty(); }
|
||||
@Override
|
||||
@@ -408,10 +439,12 @@ public class MAPS
|
||||
}
|
||||
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.synchronize(map.descendingMap()); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE descendingMap() { return MAPS.unmodifiable(map.descendingMap()); }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE navigableKeySet() { return SETS.unmodifiable(map.navigableKeySet()); }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() { return SETS.unmodifiable(map.keySet()); }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { return SETS.unmodifiable(map.descendingKeySet()); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return MAPS.unmodifiable(map.firstEntry()); }
|
||||
@@ -460,7 +493,7 @@ public class MAPS
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { return MAPS.unmodifiable(map.ceilingEntry(key)); }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,17 +524,28 @@ public class MAPS
|
||||
@Override
|
||||
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(); }
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.unmodifiable(map.keySet());
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new UnmodifyableOrderedEntrySetKV_BRACES(map.ENTRY_SET());
|
||||
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -517,24 +561,6 @@ public class MAPS
|
||||
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(); }
|
||||
@Override
|
||||
@@ -544,19 +570,21 @@ public class MAPS
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { return MAPS.unmodifiable(map.tailMap(fromKey)); }
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() { return SETS.unmodifiable(map.keySet()); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,13 +621,34 @@ public class MAPS
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) {
|
||||
VALUE_TYPE type = map.GET_VALUE(key);
|
||||
return VALUE_EQUALS(type, map.getDefaultReturnValue()) && !map.containsKey(key) ? getDefaultReturnValue() : type;
|
||||
}
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
@@ -620,6 +669,45 @@ public class MAPS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Unmodifyable Ordered Set implementation for the Unmodifyable Ordered Map implementation
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
public static class UnmodifyableOrderedEntrySet KEY_VALUE_GENERIC_TYPE extends UnmodifyableEntrySet KEY_VALUE_GENERIC_TYPE implements ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>
|
||||
{
|
||||
ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> set;
|
||||
|
||||
UnmodifyableOrderedEntrySet(ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> c) {
|
||||
super(c);
|
||||
set = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean addAndMoveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> copy() { return set.copy(); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ObjectIterators.unmodifiable(set.iterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { return ObjectIterators.unmodifiable(set.iterator(fromElement)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() { return set.first(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() { return set.last(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The Unmodifyable Set implementation for the Unmodifyable Map implementation
|
||||
* @Type(T)
|
||||
@@ -678,9 +766,11 @@ public class MAPS
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE descendingKeySet() { synchronized(mutex) { return SETS.synchronize(map.descendingKeySet(), mutex); } }
|
||||
@Override
|
||||
public NAVIGABLE_SET KEY_GENERIC_TYPE keySet() { synchronized(mutex) { return SETS.synchronize(map.keySet(), mutex); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
||||
@Override
|
||||
@@ -714,8 +804,8 @@ public class MAPS
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE ceilingEntry(KEY_TYPE key) { synchronized(mutex) { return map.ceilingEntry(key); } }
|
||||
@Override
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
#if !TYPE_OBJECT
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE subMap(CLASS_TYPE fromKey, boolean fromInclusive, CLASS_TYPE toKey, boolean toInclusive) { synchronized(mutex) { return MAPS.synchronize(map.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } }
|
||||
@@ -812,7 +902,18 @@ public class MAPS
|
||||
@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(); }
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = ObjectSets.synchronize(map.ENTRY_SET(), mutex);
|
||||
return (ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySet;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -833,24 +934,6 @@ public class MAPS
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToFirst(key, value); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToFirst(key); } }
|
||||
@Override
|
||||
@Deprecated
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { synchronized(mutex) { return map.getAndMoveToLast(key); } }
|
||||
@Override
|
||||
public COMPARATOR KEY_GENERIC_TYPE comparator() { synchronized(mutex) { return map.comparator(); } }
|
||||
@Override
|
||||
@@ -860,6 +943,8 @@ public class MAPS
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE tailMap(KEY_TYPE fromKey) { synchronized(mutex) { return MAPS.synchronize(map.tailMap(fromKey), mutex); } }
|
||||
@Override
|
||||
public SORTED_SET KEY_GENERIC_TYPE keySet() { synchronized(mutex) { return SETS.synchronize(map.keySet(), mutex); } }
|
||||
@Override
|
||||
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(); } }
|
||||
@@ -872,7 +957,7 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public SORTED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -976,6 +1061,8 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
|
||||
@Override
|
||||
public void BULK_MERGE(MAP KEY_VALUE_GENERIC_TYPE m, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { map.BULK_MERGE(m, mappingFunction); } }
|
||||
@@ -986,9 +1073,9 @@ public class MAPS
|
||||
@Override
|
||||
public void forEach(BI_CONSUMER KEY_VALUE_GENERIC_TYPE action) { synchronized(mutex) { map.forEach(action); } }
|
||||
@Override
|
||||
public int size() { synchronized(mutex) { return super.size(); } }
|
||||
public int size() { synchronized(mutex) { return map.size(); } }
|
||||
@Override
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
public MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
@Override
|
||||
public SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
|
||||
@@ -7,6 +7,8 @@ public class HashUtil
|
||||
{
|
||||
/** Minimum HashMap Capacity */
|
||||
public static final int DEFAULT_MIN_CAPACITY = 16;
|
||||
/** Minimum ConcurrentHashMap Concurrency */
|
||||
public static final int DEFAULT_MIN_CONCURRENCY = 4;
|
||||
/** Default HashMap Load Factor */
|
||||
public static final float DEFAULT_LOAD_FACTOR = 0.75F;
|
||||
/** HashMap Load Factor with reduced hash collisions but more memory usage */
|
||||
|
||||
@@ -123,8 +123,8 @@ public abstract class BaseIntIterableTest
|
||||
@Test
|
||||
public void testStreamMap() {
|
||||
if(getValidIterableTests().contains(IterableTest.STREAM_MAP)) {
|
||||
Integer[] expected = IntStream.of(TEST_ARRAY).mapToObj(Integer::new).toArray(Integer[]::new);
|
||||
Integer[] actual = ObjectIterators.pour(create(TEST_ARRAY).map(Integer::new).iterator()).toArray(Integer[]::new);
|
||||
Integer[] expected = IntStream.of(TEST_ARRAY).mapToObj(Integer::valueOf).toArray(Integer[]::new);
|
||||
Integer[] actual = ObjectIterators.pour(create(TEST_ARRAY).map(Integer::valueOf).iterator()).toArray(Integer[]::new);
|
||||
ObjectArrays.stableSort(actual);
|
||||
Assert.assertArrayEquals(expected, actual);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package speiger.src.collections.objects.list;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -8,14 +11,18 @@ import com.google.common.collect.testing.TestStringListGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.ListFeature;
|
||||
import com.google.common.collect.testing.testers.ListListIteratorTester;
|
||||
import com.google.common.collect.testing.testers.ListSubListTester;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.ints.lists.CopyOnWriteIntArrayList;
|
||||
import speiger.src.collections.ints.lists.ImmutableIntList;
|
||||
import speiger.src.collections.ints.lists.IntArrayList;
|
||||
import speiger.src.collections.ints.lists.IntLinkedList;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.objects.lists.CopyOnWriteObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ImmutableObjectList;
|
||||
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||
import speiger.src.collections.objects.lists.ObjectLinkedList;
|
||||
@@ -28,9 +35,11 @@ public class ObjectListTests extends TestCase
|
||||
TestSuite suite = new TestSuite("Lists");
|
||||
suite.addTest(suite("ArrayList", T -> new ObjectArrayList<>(T)));
|
||||
suite.addTest(suite("LinkedList", T -> new ObjectLinkedList<>(T)));
|
||||
suite.addTest(copyOnWriteSuite("CopyOnWriteArrayList", T -> new CopyOnWriteObjectArrayList<>(T)));
|
||||
suite.addTest(immutableSuite("ImmutableList", T -> new ImmutableObjectList<>(T)));
|
||||
suite.addTest(intSuite("IntArrayList", IntArrayList::new));
|
||||
suite.addTest(intSuite("IntLinkedList", IntLinkedList::new));
|
||||
suite.addTest(intCopyOnWriteSuite("CopyOnWriteArrayList", CopyOnWriteIntArrayList::new));
|
||||
suite.addTest(intImmutableSuite("IntImmutableList", ImmutableIntList::new));
|
||||
return suite;
|
||||
}
|
||||
@@ -39,6 +48,10 @@ public class ObjectListTests extends TestCase
|
||||
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test intCopyOnWriteSuite(String name, Function<int[], IntList> factory) {
|
||||
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).suppressing(suppressForCopyOnWriteArrayList()).withFeatures(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test intImmutableSuite(String name, Function<int[], IntList> factory) {
|
||||
return ListTestSuiteBuilder.using(new TestIntListGenerator(factory)).named(name).withFeatures(CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
@@ -50,10 +63,21 @@ public class ObjectListTests extends TestCase
|
||||
}).named(name).withFeatures(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test copyOnWriteSuite(String name, Function<String[], List<String>> factory) {
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).suppressing(suppressForCopyOnWriteArrayList()).withFeatures(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, CollectionFeature.SUPPORTS_ADD, CollectionFeature.SUPPORTS_REMOVE, CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Test immutableSuite(String name, Function<String[], List<String>> factory) {
|
||||
return ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) { return factory.apply(elements); }
|
||||
}).named(name).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES, CollectionSize.ANY).createTestSuite();
|
||||
}
|
||||
|
||||
public static Collection<Method> suppressForCopyOnWriteArrayList() {
|
||||
return Arrays.asList(ListSubListTester.getSubListSubListRemoveAffectsOriginalLargeListMethod(), ListListIteratorTester.getListIteratorFullyModifiableMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.common.collect.testing.features.MapFeature;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.objects.maps.impl.concurrent.Object2ObjectConcurrentOpenHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.customHash.Object2ObjectOpenCustomHashMap;
|
||||
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
|
||||
@@ -42,6 +43,7 @@ public class ObjectMapTests extends TestCase
|
||||
suite.addTest(suite("LinkedHashMap", Object2ObjectLinkedOpenHashMap::new, true));
|
||||
suite.addTest(suite("CustomHashMap", () -> new Object2ObjectOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("LinkedCustomHashMap", () -> new Object2ObjectLinkedOpenCustomHashMap<>(Strategy.INSTANCE), true));
|
||||
suite.addTest(suite("ConcurrentHashMap", Object2ObjectConcurrentOpenHashMap::new, true));
|
||||
suite.addTest(navigableSuite("RBTreeMap_NonNull", Object2ObjectRBTreeMap::new, false));
|
||||
suite.addTest(navigableSuite("AVLTreeMap_NonNull", Object2ObjectAVLTreeMap::new, false));
|
||||
suite.addTest(navigableSuite("RBTreeMap_Null", () -> new Object2ObjectRBTreeMap<>(new NullFriendlyComparator()), true));
|
||||
|
||||
Reference in New Issue
Block a user