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 af10a7d0..ba0a607f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayFIFOQueue.template @@ -1,7 +1,7 @@ package speiger.src.collections.PACKAGE.queues; -#if TYPE_OBJECT import java.util.Arrays; +#if TYPE_OBJECT import java.util.Comparator; import java.util.function.Consumer; #endif @@ -222,6 +222,15 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE implements PRIORITY_DEQUEUE KEY_G @Override public void onChanged() {} + @Override + public ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE copy() { + ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_FIFO_QUEUEBRACES(); + queue.first = first; + queue.last = last; + queue.array = Arrays.copyOf(array, array.length); + return queue; + } + @Override public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return null; } diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template index 27aca973..b0326fca 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/ArrayPriorityQueue.template @@ -322,6 +322,16 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY return new Iter(); } + @Override + public ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { + ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new ARRAY_PRIORITY_QUEUEBRACES(); + queue.firstIndex = firstIndex; + queue.size = size; + queue.comparator = comparator; + queue.array = Arrays.copyOf(array, array.length); + return queue; + } + @Override public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return comparator; diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template index e4372e6a..662195c7 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/HeapPriorityQueue.template @@ -319,6 +319,15 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE implements PRIORITY_QUEUE KEY_ ARRAYS.shiftDown(array, size, 0, comparator); } + @Override + public HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE copy() { + HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE queue = new HEAP_PRIORITY_QUEUEBRACES(); + queue.size = size; + queue.comparator = comparator; + queue.array = Arrays.copyOf(array, array.length); + return queue; + } + @Override public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { return comparator; diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template index 044109a3..b6edb168 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityDequeue.template @@ -22,4 +22,7 @@ public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GE * @return the Last Element within the dequeue without deleting it */ public default KEY_TYPE last() { return peek(size()-1); } + + @Override + public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy(); } \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template index 7681e2ed..8d0df4e4 100644 --- a/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template +++ b/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template @@ -70,6 +70,15 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY */ public void onChanged(); + /** + * A Function that does a shallow clone of the PriorityQueue itself. + * This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted. + * It can be compared to Cloneable but with less exception risk + * @return a Shallow Copy of the PriorityQueue + * @note Wrappers and view PriorityQueues will not support this feature + */ + public PRIORITY_QUEUE KEY_GENERIC_TYPE copy(); + /** * @return the sorter of the Queue, can be null */ 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 6f806c7d..5c3e2eff 100644 --- a/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template +++ b/src/builder/resources/speiger/assets/collections/templates/utils/PriorityQueues.template @@ -100,6 +100,8 @@ public class PRIORITY_QUEUES public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator() { synchronized(mutex) { return queue.comparator(); } } @Override 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(); } } /** @@ -123,5 +125,7 @@ public class PRIORITY_QUEUES public void enqueueFirst(KEY_TYPE e) { synchronized(mutex) { dequeue.enqueueFirst(e); } } @Override public KEY_TYPE dequeueLast() { synchronized(mutex) { return dequeue.dequeueLast(); } } + @Override + public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } } }