Package de.geolykt.starloader.deobf
Class LIFOQueue<E>
java.lang.Object
de.geolykt.starloader.deobf.LIFOQueue<E>
- Type Parameters:
E- The type of elements that should be stored in the queue.
- All Implemented Interfaces:
Iterable<E>
A Last-in-first-out (LIFO) queue that uses a Deque as a delegate. Technically
the
Deque can be used directly, however the issue is that there is a
rather high chance of logical programmer errors as Queue.add(Object)
does not specify the insertion order and ArrayDeque.add(Object) adds
the element to the tail of the queue and not to the head as it might be
expected. This class resolves that issue.
Alternatively the Stack class could be used as a LIFO queue, however
it has the drawbacks of almost every method being synchronised and thus not
being very good in concurrent environments as well of implementing
Deque and thus also inheriting the above stated issue.
- Author:
- Geolykt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCallsDeque.addFirst(Object), which adds an element to the head of the queue.voidclear()Clears all elements from the queue.booleanObtains the dequeue delegate for more advanced operations.Obtains theLinkedListdelegate for more advanced operations.getHead()Obtains the element at the head of the queue, if there is no such element then aNoSuchElementExceptionwill be thrown.intgetSize()Obtains the amount of elements left in the queue.inthashCode()booleanisEmpty()Checks whether the queue is empty.iterator()remove()CallsDeque.remove()and thus throws an exception if there is no element left in the queue.toString()
-
Constructor Details
-
LIFOQueue
-
-
Method Details
-
add
CallsDeque.addFirst(Object), which adds an element to the head of the queue. If the underlying Dequeue has capacity restrictions, it throws anIllegalStateException. Some Dequeues (such asArrayDeque) may not accept null elements and will throw aNullPointerException, which would be propagated by this method.- Parameters:
element- The element to add
-
clear
public void clear()Clears all elements from the queue. -
equals
-
getDelegate
Obtains the dequeue delegate for more advanced operations.- Returns:
- The delegate Deque
-
getDelegateList
Obtains theLinkedListdelegate for more advanced operations.- Returns:
- The delegate
LinkedList.
-
getHead
Obtains the element at the head of the queue, if there is no such element then aNoSuchElementExceptionwill be thrown. This method callsDeque.getFirst().- Returns:
- The element at the head of the queue.
- Throws:
NoSuchElementException- If there are no elements in the queue.
-
getSize
public int getSize()Obtains the amount of elements left in the queue.- Returns:
- The amount of elements in the queue
- See Also:
-
hashCode
public int hashCode() -
isEmpty
public boolean isEmpty()Checks whether the queue is empty. This method corresponds toCollection.isEmpty(). This method should generally only return true isgetSize()is equal to 0.- Returns:
- False if there is at least one element left in the queue, otherwise true.
-
iterator
-
remove
CallsDeque.remove()and thus throws an exception if there is no element left in the queue. If there is an element left in the queue, the element at the head of the queue is removed from the queue and returned.- Returns:
- The removed element.
- Throws:
NoSuchElementException- If there are no elements left in the queue.
-
spliterator
- Specified by:
spliteratorin interfaceIterable<E>
-
toString
-