105 lines
3.5 KiB
Plaintext
105 lines
3.5 KiB
Plaintext
package speiger.src.collections.PACKAGE.queues;
|
|
|
|
#if TYPE_OBJECT
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
#endif
|
|
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
|
#if QUEUES_FEATURE
|
|
import speiger.src.collections.PACKAGE.utils.PRIORITY_QUEUES;
|
|
#endif
|
|
|
|
/**
|
|
* A Type Speciifc PriorityDeque or Dequeue interface to allow implementations like FIFO queues.
|
|
* @Type(T)
|
|
*/
|
|
public interface PRIORITY_DEQUEUE KEY_GENERIC_TYPE extends PRIORITY_QUEUE KEY_GENERIC_TYPE
|
|
{
|
|
/**
|
|
* Method to insert a element into the first Index instead of the last.
|
|
* @param e the element that should be inserted into the first place
|
|
*/
|
|
public void enqueueFirst(KEY_TYPE e);
|
|
|
|
/**
|
|
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
|
* @param e the elements that should be inserted
|
|
*/
|
|
public default void enqueueAllFirst(KEY_TYPE... e) {
|
|
enqueueAllFirst(e, 0, e.length);
|
|
}
|
|
|
|
/**
|
|
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
|
* @param e the elements that should be inserted
|
|
* @param length the amount of elements that should be inserted
|
|
*/
|
|
public default void enqueueAllFirst(KEY_TYPE[] e, int length) {
|
|
enqueueAllFirst(e, 0, length);
|
|
}
|
|
|
|
/**
|
|
* Method to mass insert a elements into the first Index of the PriorityDequeue.
|
|
* @param e the elements that should be inserted
|
|
* @param offset the offset where in the array should be started
|
|
* @param length the amount of elements that should be inserted
|
|
*/
|
|
public default void enqueueAllFirst(KEY_TYPE[] e, int offset, int length) {
|
|
for(int i = 0;i<length;i++)
|
|
enqueueFirst(e[i+offset]);
|
|
}
|
|
|
|
/**
|
|
* Method to mass insert elements into first Index of the PriorityDequeue.
|
|
* @param c the elements that should be inserted from the Collection
|
|
*/
|
|
public default void enqueueAllFirst(COLLECTION KEY_GENERIC_TYPE c) {
|
|
for(ITERATOR KEY_GENERIC_TYPE iter = c.iterator();iter.hasNext();)
|
|
enqueueFirst(iter.NEXT());
|
|
}
|
|
|
|
#if TYPE_OBJECT
|
|
/**
|
|
* Method to mass insert elements into first Index of the PriorityDequeue.
|
|
* This method exists to add support for Java Collections to make it more useable
|
|
* @param c the elements that should be inserted from the Collection
|
|
*/
|
|
public default void enqueueAllFirst(Collection<? extends CLASS_TYPE> c) {
|
|
for(Iterator<? extends CLASS_TYPE> iter = c.iterator();iter.hasNext();)
|
|
enqueueFirst(iter.next());
|
|
}
|
|
|
|
#endif
|
|
/**
|
|
* A Method to remove a element from the last place instead of the first
|
|
* @return the last element inserted
|
|
* @throws java.util.NoSuchElementException if no element is in the deque
|
|
*/
|
|
public KEY_TYPE dequeueLast();
|
|
/**
|
|
* Peeking function for the last element
|
|
* @return the Last Element within the dequeue without deleting it
|
|
*/
|
|
public default KEY_TYPE last() { return peek(size()-1); }
|
|
|
|
#if QUEUES_FEATURE
|
|
/**
|
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
|
* @return a new PriorityDequeue that is synchronized
|
|
* @see PRIORITY_QUEUES#synchronize
|
|
*/
|
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue() { return PRIORITY_QUEUES.synchronize(this); }
|
|
|
|
/**
|
|
* Creates a Wrapped PriorityDequeue that is Synchronized
|
|
* @param mutex is the controller of the synchronization block
|
|
* @return a new PriorityDequeue Wrapper that is synchronized
|
|
* @see PRIORITY_QUEUES#synchronize
|
|
*/
|
|
public default PRIORITY_DEQUEUE KEY_GENERIC_TYPE synchronizeQueue(Object mutex) { return PRIORITY_QUEUES.synchronize(this, mutex); }
|
|
|
|
#endif
|
|
@Override
|
|
public PRIORITY_DEQUEUE KEY_GENERIC_TYPE copy();
|
|
} |