Class List2<T>

java.lang.Object
components.list.ListSecondary<T>
components.list.List2<T>
Type Parameters:
T - type of List entries
All Implemented Interfaces:
List<T>, ListKernel<T>, Standard<List<T>>, Iterable<T>

public class List2<T> extends ListSecondary<T>
List 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.leftLength >= 0  and
[$this.rightLength >= 0] and
[$this.preStart is not null]  and
[$this.lastLeft is not null]  and
[$this.finish is not null]  and
[$this.preStart points to the first node of a singly linked list
 containing $this.leftLength + $this.rightLength + 1 nodes]  and
[$this.lastLeft points to the ($this.leftLength + 1)-th node in
 that singly linked list]  and
[$this.finish points to the last node in that singly linked list]  and
[$this.finish.next is null]
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.finish])
  • Constructor Summary

    Constructors
    Constructor
    Description
    No-argument constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Adds x to the beginning of this.right.
    final void
    Advances the position in this by one.
    final void
    Resets this to an initial value.
    final Iterator<T>
     
    final int
    Reports length of this.left.
    final void
    Moves the position in this to the end.
    final void
    Moves the position in this to the beginning.
    final List2<T>
    Returns a new object with the same dynamic type as this, having an initial value.
    final T
    Removes and returns the entry at the front of this.right.
    final T
    Replaces the entry at the front of this.right with x, and returns the old entry.
    final T
    Reports the front of this.right.
    final int
    Reports length of this.right.
    final void
    transferFrom(List<T> source)
    Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this.

    Methods inherited from class components.list.ListSecondary

    equals, hashCode, retreat, 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

    • List2

      public List2()
      No-argument constructor.
  • Method Details

    • newInstance

      public final List2<T> newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T 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 initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(List<T> source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • addRightFront

      public final void addRightFront(T x)
      Description copied from interface: ListKernel
      Adds x to the beginning of this.right.
      Parameters:
      x - the entry to be added
    • removeRightFront

      public final T removeRightFront()
      Description copied from interface: ListKernel
      Removes and returns the entry at the front of this.right.
      Returns:
      the front entry of this.right
    • advance

      public final void advance()
      Description copied from interface: ListKernel
      Advances the position in this by one.
    • moveToStart

      public final void moveToStart()
      Description copied from interface: ListKernel
      Moves the position in this to the beginning.
    • rightLength

      public final int rightLength()
      Description copied from interface: ListKernel
      Reports length of this.right.
      Returns:
      the length of this.right
    • leftLength

      public final int leftLength()
      Description copied from interface: ListKernel
      Reports length of this.left.
      Returns:
      the length of this.left
    • iterator

      public final Iterator<T> iterator()
    • rightFront

      public final T rightFront()
      Description copied from interface: List
      Reports the front of this.right.
      Specified by:
      rightFront in interface List<T>
      Overrides:
      rightFront in class ListSecondary<T>
      Returns:
      the front entry of this.right
    • replaceRightFront

      public final T replaceRightFront(T x)
      Description copied from interface: List
      Replaces the entry at the front of this.right with x, and returns the old entry.
      Specified by:
      replaceRightFront in interface List<T>
      Overrides:
      replaceRightFront in class ListSecondary<T>
      Parameters:
      x - the new entry
      Returns:
      the old front entry of this.right
    • moveToFinish

      public final void moveToFinish()
      Description copied from interface: List
      Moves the position in this to the end.
      Specified by:
      moveToFinish in interface List<T>
      Overrides:
      moveToFinish in class ListSecondary<T>