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

121 lines
3.7 KiB
Plaintext

package speiger.src.collections.PACKAGE.queues;
#if TYPE_OBJECT
import java.util.Comparator;
#else
import speiger.src.collections.PACKAGE.collections.ITERABLE;
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
import speiger.src.collections.objects.queues.ObjectPriorityQueue;
#endif
/**
* A Simple PriorityQueue (or Queue) interface that provides with the nessesary functions to interact with it, without cluttering with the Collection interface.
* @Type(T)
*/
#if TYPE_OBJECT
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends Iterable<KEY_TYPE>
#else
public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ObjectPriorityQueue<CLASS_TYPE>, ITERABLE KEY_GENERIC_TYPE
#endif
{
#if TYPE_OBJECT
/**
* @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();
#endif
/**
* 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_KEY() { 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 REMOVE(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 REMOVE_LAST(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
*/
@PrimitiveOverride
public COMPARATOR KEY_SUPER_GENERIC_TYPE comparator();
/**
* A method to drop the contents of the Queue without clearing the queue
* @return the contents of the queue into a seperate array.
*/
public default KEY_TYPE[] TO_ARRAY() { return TO_ARRAY(NEW_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
* @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_TYPE[] TO_ARRAY(KEY_TYPE[] input);
#if !TYPE_OBJECT
@Deprecated
public default void enqueue(CLASS_TYPE e) { ENQUEUE(OBJ_TO_KEY(e)); }
@Deprecated
public default CLASS_TYPE dequeue() { return KEY_TO_OBJ(DEQUEUE()); }
@Deprecated
public default CLASS_TYPE peek(int index) { return KEY_TO_OBJ(PEEK(index)); }
@Deprecated
public default CLASS_TYPE first() { return peek(0); }
@Deprecated
public default boolean remove(CLASS_TYPE e) { return REMOVE(OBJ_TO_KEY(e)); }
@Deprecated
public default boolean removeLast(CLASS_TYPE e) { return REMOVE_LAST(OBJ_TO_KEY(e)); }
@Deprecated
public default CLASS_TYPE[] toArray() { return toArray(new CLASS_TYPE[size()]); }
@Deprecated
public CLASS_TYPE[] toArray(CLASS_TYPE[] input);
#endif
}