Package components.queue
Class Queue2<T>
java.lang.Object
components.queue.QueueSecondary<T>
components.queue.Queue2<T>
- Type Parameters:
T
- type ofQueue
entries
- All Implemented Interfaces:
Queue<T>
,QueueKernel<T>
,Standard<Queue<T>>
,Iterable<T>
Queue
represented as a singly linked list, done "bare-handed", with
implementations of primary methods.
Execution-time performance of all methods implemented in this class is O(1).
- Representation Invariant (concrete invariant of $this):
$this.length >= 0 and [$this.preFront is not null] and [$this.rear is not null] and [$this.preFront points to the first node of a singly linked list containing $this.length + 1 nodes] and [$this.rear points to the last node in that singly linked list] and [$this.rear.next is null]
- Abstraction Relation (interpretation mapping between $this and this):
this = [data in nodes starting at $this.preFront.next and running through $this.rear]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
Resetsthis
to an initial value.final T
dequeue()
Removes and returns the entry at the front ofthis
.final void
Addsx
to the end ofthis
.iterator()
final int
length()
Reports length ofthis
.Returns a new object with the same dynamic type asthis
, having an initial value.final T
replaceFront
(T x) Replaces the front ofthis
withx
, and returns the old front.final void
transferFrom
(Queue<T> source) Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
.Methods inherited from class components.queue.QueueSecondary
append, equals, flip, front, hashCode, rotate, sort, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Queue2
public Queue2()No-argument constructor.
-
-
Method Details
-
newInstance
Description copied from interface:Standard
Returns a new object with the same dynamic type asthis
, having an initial value. If the typeT
has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initializethis
.- Returns:
- new object "like"
this
with an initial value
-
clear
Description copied from interface:Standard
Resetsthis
to an initial value. If the typeT
has a no-argument constructor, thenthis
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thenthis
satisfies the contract of the constructor call that was used to initialize#this
. -
transferFrom
Description copied from interface:Standard
Setsthis
to the incoming value ofsource
, and resetssource
to an initial value; the declaration notwithstanding, the dynamic type ofsource
must be the same as the dynamic type ofthis
. If the typeT
has a no-argument constructor, thensource
satisfies the contract of the no-argument constructor forT
. IfT
does not have a no-argument constructor, thensource
satisfies the contract of the constructor call that was used to initialize#source
.- Parameters:
source
- object whose value is to be transferred
-
enqueue
Description copied from interface:QueueKernel
Addsx
to the end ofthis
.- Parameters:
x
- the entry to be added
-
dequeue
Description copied from interface:QueueKernel
Removes and returns the entry at the front ofthis
.- Returns:
- the entry removed
-
length
Description copied from interface:QueueKernel
Reports length ofthis
.- Returns:
- the length of
this
-
iterator
-
replaceFront
Description copied from interface:Queue
Replaces the front ofthis
withx
, and returns the old front.- Specified by:
replaceFront
in interfaceQueue<T>
- Overrides:
replaceFront
in classQueueSecondary<T>
- Parameters:
x
- the new front entry- Returns:
- the old front entry
-