Package components.list
Class List3<T>
java.lang.Object
components.list.ListSecondary<T>
components.list.List3<T>
- Type Parameters:
T
- type ofList
entries
- All Implemented Interfaces:
List<T>
,ListKernel<T>
,Standard<List<T>>
,Iterable<T>
List
represented as a doubly 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.leftLength >= 0 and [$this.rightLength >= 0] and [$this.preStart is not null] and [$this.lastLeft is not null] and [$this.postFinish is not null] and [$this.preStart points to the first node of a doubly linked list containing ($this.leftLength + $this.rightLength + 2) nodes] and [$this.lastLeft points to the ($this.leftLength + 1)-th node in that doubly linked list] and [$this.postFinish points to the last node in that doubly linked list] and [for every node n in the doubly linked list of nodes, except the one pointed to by $this.preStart, n.previous.next = n] and [for every node n in the doubly linked list of nodes, except the one pointed to by $this.postFinish, n.next.previous = n]
- Abstraction Relation (interpretation mapping between $this and this):
this = ([data in nodes starting at $this.preStart.next and running through $this.lastLeft], [data in nodes starting at $this.lastLeft.next and running through $this.postFinish.previous])
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addRightFront
(T x) Addsx
to the beginning ofthis.right
.final void
advance()
Advances the position inthis
by one.final void
clear()
Resetsthis
to an initial value.iterator()
final int
Reports length ofthis.left
.final void
Moves the position inthis
to the end.final void
Moves the position inthis
to the beginning.Returns a new object with the same dynamic type asthis
, having an initial value.final T
Removes and returns the entry at the front ofthis.right
.final T
Replaces the entry at the front ofthis.right
withx
, and returns the old entry.final void
retreat()
Retreats the position inthis
by one.final T
Reports the front ofthis.right
.final int
Reports length ofthis.right
.final void
transferFrom
(List<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.list.ListSecondary
equals, hashCode, swapRights, 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
-
List3
public List3()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
-
addRightFront
Description copied from interface:ListKernel
Addsx
to the beginning ofthis.right
.- Parameters:
x
- the entry to be added
-
removeRightFront
Description copied from interface:ListKernel
Removes and returns the entry at the front ofthis.right
.- Returns:
- the front entry of
this.right
-
advance
Description copied from interface:ListKernel
Advances the position inthis
by one. -
moveToStart
Description copied from interface:ListKernel
Moves the position inthis
to the beginning. -
leftLength
Description copied from interface:ListKernel
Reports length ofthis.left
.- Returns:
- the length of
this.left
-
rightLength
Description copied from interface:ListKernel
Reports length ofthis.right
.- Returns:
- the length of
this.right
-
iterator
-
rightFront
Description copied from interface:List
Reports the front ofthis.right
.- Specified by:
rightFront
in interfaceList<T>
- Overrides:
rightFront
in classListSecondary<T>
- Returns:
- the front entry of
this.right
-
replaceRightFront
Description copied from interface:List
Replaces the entry at the front ofthis.right
withx
, and returns the old entry.- Specified by:
replaceRightFront
in interfaceList<T>
- Overrides:
replaceRightFront
in classListSecondary<T>
- Parameters:
x
- the new entry- Returns:
- the old front entry of
this.right
-
moveToFinish
Description copied from interface:List
Moves the position inthis
to the end.- Specified by:
moveToFinish
in interfaceList<T>
- Overrides:
moveToFinish
in classListSecondary<T>
-
retreat
Description copied from interface:List
Retreats the position inthis
by one.
-