From a38e7b069a2d3d3a664464396a7bfb83feea6357 Mon Sep 17 00:00:00 2001 From: Speiger Date: Thu, 7 Oct 2021 14:50:52 +0200 Subject: [PATCH] More Consistency and more features. - Added: Wrapper now support the Optimized Lambda replacer functions to improve performance. - Added: FIFO Queue has now a minimum capacity and that is now checked more consistently. - Added: Changelog & Version Bump --- Changelog.md | 4 +++ README.md | 3 ++- build.gradle | 2 +- .../templates/queues/ArrayFIFOQueue.template | 16 +++++++---- .../templates/utils/Collections.template | 27 ++++++++++++++++++- .../templates/utils/PriorityQueues.template | 20 ++++++++++++++ 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index fe065ba4..6e564c0e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog of versions +### Version 0.4.3 +- Added: Wrapper now support the Optimized Lambda replacer functions to improve performance. +- Added: FIFO Queue has now a minimum capacity and that is now checked more consistently. + ### Version 0.4.2 - Added: Lists/Sets/Maps/PriorityQueues are now copy-able. with the new copy() function. Note: subLists/subMaps/subSets or synchronize/unmodifyable wrappers do not support that function. diff --git a/README.md b/README.md index 3e04c3d2..28e65bb1 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,14 @@ repositories { } } dependencies { - compile 'de.speiger:Primitive-Collections:0.4.2' + compile 'de.speiger:Primitive-Collections:0.4.3' } ``` Direct: | Version | Jar | Sources | Java Doc | |--------- |------------------------------------------------------------------------------------------------------------------------------ |-------------------------------------------------------------------------------------------------------------------------------------- |-------------------------------------------------------------------------------------------------------------------------------------- | +| 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) | diff --git a/build.gradle b/build.gradle index 15a14e6e..31b08df5 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ repositories { } archivesBaseName = 'Primitive Collections' -version = '0.4.2'; +version = '0.4.3'; sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template index d6fbd980..65f5b2f2 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -34,6 +34,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K protected int first; /** The Last Index pointer */ protected int last; + /** The Minimum Capacity of the Queue **/ + protected int minCapacity; /** * Constructor using a initial array @@ -62,7 +64,9 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K */ public ARRAY_FIFO_QUEUE(KEY_TYPE[] values, int offset, int size) { if (values.length < size) throw new IllegalArgumentException("Initial array (" + values.length + ") is smaller then the expected size (" + size + ")"); - if(values.length <= 0) values = NEW_KEY_ARRAY(1); + if(values.length <= 0) values = NEW_KEY_ARRAY(MIN_CAPACITY); + else if(values.length < MIN_CAPACITY) values = Arrays.copyOf(values, MIN_CAPACITY); + minCapacity = MIN_CAPACITY; array = values; first = offset; last = (offset + size) % array.length; @@ -76,7 +80,8 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K */ public ARRAY_FIFO_QUEUE(int capacity) { if (capacity < 0) throw new IllegalArgumentException("Initial capacity (" + capacity + ") is negative"); - array = NEW_KEY_ARRAY(Math.max(1, capacity)); + array = NEW_KEY_ARRAY(Math.max(MIN_CAPACITY, capacity)); + minCapacity = array.length; } /** @@ -227,6 +232,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES(); queue.first = first; queue.last = last; + queue.minCapacity = minCapacity; queue.array = Arrays.copyOf(array, array.length); return queue; } @@ -305,7 +311,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K @Override public boolean trim(int size) { - int newSize = Math.max(size, size()); + int newSize = Math.max(Math.max(size, size()), minCapacity); if(newSize >= array.length) return false; KEY_TYPE[] newArray = NEW_KEY_ARRAY(newSize); if(first <= last) System.arraycopy(array, first, newArray, 0, last - first); @@ -326,7 +332,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K */ @Override public void clearAndTrim(int size) { - int newSize = Math.max(MIN_CAPACITY, size); + int newSize = Math.max(minCapacity, size); if(array.length <= newSize) { clear(); return; @@ -348,7 +354,7 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K protected void reduce() { final int size = size(); - if (array.length > MIN_CAPACITY && size <= array.length / 4) resize(size, array.length / 2); + if (array.length > minCapacity && size <= array.length / 4) resize(size, Math.max(array.length / 2, minCapacity)); } protected void expand() { diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template index e8ac51f0..089ac445 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/Collections.template @@ -15,7 +15,8 @@ import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.PACKAGE.functions.CONSUMER; import speiger.src.collections.PACKAGE.utils.ARRAYS; #endif - +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; /** * A Helper class for Collections */ @@ -180,6 +181,18 @@ public class COLLECTIONS public boolean equals(Object obj) { synchronized(mutex) { return c.equals(obj); } } @Override public String toString() { synchronized(mutex) { return c.toString(); } } + @Override + public void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE action) { synchronized(mutex) { c.forEach(input, action); } } + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAny(filter); } } + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesNone(filter); } } + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.matchesAll(filter); } } + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.findFirst(filter); } } + @Override + public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } } } /** @@ -278,6 +291,18 @@ public class COLLECTIONS public boolean equals(Object obj) { return c.equals(obj); } @Override public String toString() { return c.toString(); } + @Override + public void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE action) { c.forEach(input, action); } + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAny(filter); } + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesNone(filter); } + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { return c.matchesAll(filter); } + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { return c.findFirst(filter); } + @Override + public int count(PREDICATE KEY_GENERIC_TYPE filter) { return c.count(filter); } } /** diff --git a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template index 5c3e2eff..80471bac 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template @@ -2,6 +2,7 @@ package speiger.src.collections.PACKAGE.utils; #if TYPE_OBJECT import java.util.Comparator; +import java.util.function.Consumer; #endif import speiger.src.collections.PACKAGE.collections.ITERATOR; @@ -10,6 +11,11 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR; #endif import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE; import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.CONSUMER; +#endif +import speiger.src.collections.PACKAGE.functions.function.PREDICATE; +import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER; /** * A Helper class for PriorityQueues @@ -102,6 +108,20 @@ public class PRIORITY_QUEUES public GENERIC_SPECIAL_KEY_BRACES KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input) { synchronized(mutex) { return queue.TO_ARRAY(input); } } @Override public PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + @Override + public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(action); } } + @Override + public void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE action) { synchronized(mutex) { queue.forEach(input, action); } } + @Override + public boolean matchesAny(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAny(filter); } } + @Override + public boolean matchesNone(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesNone(filter); } } + @Override + public boolean matchesAll(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.matchesAll(filter); } } + @Override + public KEY_TYPE findFirst(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.findFirst(filter); } } + @Override + public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return queue.count(filter); } } } /**