edu.princeton.cs.algs4.growingtree.framework
Class AffineTransformList

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.framework.AffineTransformList

public class AffineTransformList
extends java.lang.Object

Linked list implementation of the List interface containing AffineTransforms. Implements all optional list operations, but only permits AffineTransform insertion. In addition to implementing the List interface, the AffineTransformList class extends the uniformly named methods within LinkedList to get, remove and insert an element at the beginning and end of the list. These operations allow AffineTransformLists to be used as a stack, queue, or double-ended queue (deque).

The primary purpose of the class is for the development of getTransformStep, which returns the AffineTransform found passing a double index. The double index transforms into an intermidiary AffineTransform developed from the list of AffineTransforms.

The iterators returned by the this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the Iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Version:
1.4 9/01/02
Author:
Corey Sanders
See Also:
LinkedList, AffineTransform

Constructor Summary
AffineTransformList()
          Constructs an empty list.
AffineTransformList(java.util.Collection<java.awt.geom.AffineTransform> c)
          Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
 
Method Summary
 boolean add(java.awt.geom.AffineTransform a)
          Appends the given AffineTransform to the end of this list.
 void add(int index, java.awt.geom.AffineTransform element)
          Inserts the specified AffineTransform at the specified position in this list.
 void addFirst(java.awt.geom.AffineTransform a)
          Inserts the given AffineTransform at the beginning of this list.
 void addLast(java.awt.geom.AffineTransform a)
          Appends the given AffineTransform to the end of this list.
 java.awt.geom.AffineTransform get(int index)
          Gets the element at index in this list.
static java.awt.geom.AffineTransform getTransformStep(java.awt.geom.AffineTransform a, java.awt.geom.AffineTransform b, double step)
          Finds the appropriate AffineTransform given a double step and two AffineTrasforms.
 java.awt.geom.AffineTransform getTransformStep(double step)
          Finds the appropriate AffineTransform given a double step.
 java.awt.geom.AffineTransform set(int index, java.awt.geom.AffineTransform element)
          Replaces the AffineTransform at the specified position in this list with the specified AffineTransform.
 int size()
          Gets the number of elements in this list.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AffineTransformList

public AffineTransformList()
Constructs an empty list.


AffineTransformList

public AffineTransformList(java.util.Collection<java.awt.geom.AffineTransform> c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Parameters:
c - the collection whose elements are to be placed into this list.
Method Detail

size

public int size()
Gets the number of elements in this list.


get

public java.awt.geom.AffineTransform get(int index)
Gets the element at index in this list.


add

public boolean add(java.awt.geom.AffineTransform a)
Appends the given AffineTransform to the end of this list.

Parameters:
a - the AffineTransform to be inserted at the end of this list.
Returns:
true (as per the general contract of Collection.add).

add

public void add(int index,
                java.awt.geom.AffineTransform element)
Inserts the specified AffineTransform at the specified position in this list. Shifts the AffineTransform currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
element - AffineTransform to be inserted.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size()).

addFirst

public void addFirst(java.awt.geom.AffineTransform a)
Inserts the given AffineTransform at the beginning of this list.

Parameters:
a - the AffineTransform to be inserted at the beginning of this list.

addLast

public void addLast(java.awt.geom.AffineTransform a)
Appends the given AffineTransform to the end of this list. (Identical in function to the add method; included only for consistency.)

Parameters:
a - the AffineTransform to be inserted at the end of this list.

set

public java.awt.geom.AffineTransform set(int index,
                                         java.awt.geom.AffineTransform element)
Replaces the AffineTransform at the specified position in this list with the specified AffineTransform.

Parameters:
index - index of element to replace.
element - AffineTransform to be stored at the specified position.
Returns:
the AffineTransform previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).

getTransformStep

public java.awt.geom.AffineTransform getTransformStep(double step)
                                               throws java.lang.IndexOutOfBoundsException
Finds the appropriate AffineTransform given a double step. The double step refers to inbetween two AffineTransforms, defined by integer indices. The AffineTransform returns that takes the step and finds the AffineTransform that fits at that given point between the two integer indices.

Parameters:
step - double step referring to inbetween two indices of the AffineTransformList.
Returns:
AffineTransform that represents the transform for the double step between two AffineTransforms.
Throws:
java.lang.IndexOutOfBoundsException - if the specified step is out of range (step < 0 || step >= size()).

getTransformStep

public static java.awt.geom.AffineTransform getTransformStep(java.awt.geom.AffineTransform a,
                                                             java.awt.geom.AffineTransform b,
                                                             double step)
Finds the appropriate AffineTransform given a double step and two AffineTrasforms. The double step refers to a number between 1 and 0. The AffineTransform returned takes the step and finds the AffineTransform that fits at that given point between the two integer indices, 0 returns AffineTransform a and 1 returns AffineTrasform b.

Parameters:
a - AffineTransform that is returned at step 0.
b - AffineTransform that is returned at step 1.
step - double step referring to inbetween two indices of the AffineTransformList.
Returns:
AffineTransform that represents the transform for the double step between two AffineTransforms a and b.
Throws:
java.lang.IndexOutOfBoundsException - if the specified step is out of range (step < 0 || step >= size()).