Primitive-Collections/src/builder/resources/speiger/assets/collections/templates/queues/PriorityQueue.template

98 lines
3.0 KiB
Plaintext

package speiger.src.collections.PACKAGE.queues;
#if TYPE_OBJECT
import java.util.Comparator;
import speiger.src.collections.objects.collections.ObjectIterator;
#else
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
#endif
import speiger.src.collections.PACKAGE.collections.ITERABLE;
/**
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
* @Type(T)
*/
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TYPE
{
/**
* @return true if the PriorityQueue is empty
*/
public default boolean isEmpty() { return size() <= 0; }
/**
* @return the amount of elements that are stored in the PriorityQueue
*/
public int size();
/**
* clears all elements within the PriorityQueue,
* this does not resize the backing arrays
*/
public void clear();
/**
* Method to insert a element into the PriorityQueue
* @param e the element that should be inserted
*/
public void enqueue(KEY_TYPE e);
/**
* Method to extract a element from the PriorityQueue
* @return a element from the Queue
* @throws java.util.NoSuchElementException if no element is present
*/
public KEY_TYPE dequeue();
/**
* Peeking function to see whats inside the queue.
* @param index of the element that is requested to be viewed.
* @return the element that is requested
*/
public KEY_TYPE peek(int index);
/**
* Shows the element that is to be returned next
* @return the first element in the Queue
*/
public default KEY_TYPE first() { return peek(0); }
/**
* Removes the first found element in the queue
* @param e the element that should be removed
* @return if a searched element was removed
*/
public boolean removeFirst(KEY_TYPE e);
/**
* Removes the last found element in the queue
* @param e the element that should be removed
* @return if a searched element was removed
*/
public boolean removeLast(KEY_TYPE e);
/**
* Allows to notify the Queue to be revalidate its data
*/
public void onChanged();
/**
* @return the sorter of the Queue, can be null
*/
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
#if TYPE_OBJECT
/**
* @return draining iterator of the PriorityQueue
*/
public ITERATOR KEY_GENERIC_TYPE iterator();
#endif
/**
* A method to drop the contents of the Queue without clearing the queue
* @Type(E)
* @return the contents of the queue into a seperate array.
*/
public default KEY_GENERIC_SPECIAL_TYPE KEY_SPECIAL_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_SPECIAL_KEY_ARRAY(size())); }
/**
* A method to drop the contents of the Queue without clearing the queue
* @param input where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
* @Type(E)
* @return the contents of the queue into a seperate array.
* @note if the Type is generic then a Object Array is created instead of a Type Array
*/
public KEY_GENERIC_SPECIAL_TYPE KEY_SPECIAL_TYPE[] TO_ARRAY(KEY_SPECIAL_TYPE[] input);
}