org.opensourcephysics.cabrillo.tracker
Class VectorChain

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<VectorStep>
              extended by org.opensourcephysics.cabrillo.tracker.VectorChain
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<VectorStep>, java.util.Collection<VectorStep>, java.util.List<VectorStep>, java.util.RandomAccess

public class VectorChain
extends java.util.ArrayList<VectorStep>

This is an ArrayList that represents a chain of vectors linked tip-to-tail.

Author:
Douglas Brown
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected VectorChain(VectorStep start)
          Constructs a chain.
  VectorChain(VectorStep start, VectorStep end)
          Constructs a chain.
 
Method Summary
 void add(int index, VectorStep v)
          Overrides ArrayList method.
 boolean add(VectorChain chain)
          Adds a VectorChain to this chain.
 boolean add(VectorStep vector)
          Ads a vector to this chain.
 boolean addAll(java.util.Collection<? extends VectorStep> c)
          Overrides ArrayList method.
 boolean addAll(int index, java.util.Collection<? extends VectorStep> c)
          Overrides ArrayList method.
 VectorChain breakAt(VectorStep vector)
          /** Attempts to break this chain in two.
 void clear()
          Overrides ArrayList method.
 VectorStep getEnd()
          Gets the end of the chain.
 VectorStep getStart()
          Gets the start of the chain.
protected  boolean isAllowed(VectorStep vector)
          Determines whether the specified vector is allowed to be added to the end hinge.
 VectorStep remove(int index)
          Overrides ArrayList method.
 boolean remove(java.lang.Object obj)
          Overrides ArrayList method.
protected  java.util.ArrayList<VectorStep> remove(VectorStep vector)
          Removes vectors downstream of and including the specified vector.
 VectorStep removeEnd()
          Removes the end of the chain.
 void removeRange(int from, int to)
          Overrides ArrayList method.
 boolean retainAll(java.util.Collection<?> c)
          Overrides ArrayList method.
 VectorStep set(int index, VectorStep obj)
          Overrides ArrayList method.
 
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, subList
 

Constructor Detail

VectorChain

protected VectorChain(VectorStep start)
Constructs a chain.

Parameters:
start - the start vector

VectorChain

public VectorChain(VectorStep start,
                   VectorStep end)
Constructs a chain.

Parameters:
start - the start vector
end - the end vector
Method Detail

getEnd

public VectorStep getEnd()
Gets the end of the chain.

Returns:
the end vector

getStart

public VectorStep getStart()
Gets the start of the chain.

Returns:
the start vector

removeEnd

public VectorStep removeEnd()
Removes the end of the chain.

Returns:
the removed end

breakAt

public VectorChain breakAt(VectorStep vector)
/** Attempts to break this chain in two. If successful, the specified vector becomes the tail vector of a new chain.

Parameters:
vector - the vector
Returns:
the new chain, if any

clear

public void clear()
Overrides ArrayList method.

Specified by:
clear in interface java.util.Collection<VectorStep>
Specified by:
clear in interface java.util.List<VectorStep>
Overrides:
clear in class java.util.ArrayList<VectorStep>

add

public boolean add(VectorStep vector)
Ads a vector to this chain.

Specified by:
add in interface java.util.Collection<VectorStep>
Specified by:
add in interface java.util.List<VectorStep>
Overrides:
add in class java.util.ArrayList<VectorStep>
Parameters:
vector - the vector to add
Returns:
true if the vector is successfully added

add

public boolean add(VectorChain chain)
Adds a VectorChain to this chain.

Parameters:
chain - the chain to add
Returns:
true if successfully added

addAll

public boolean addAll(java.util.Collection<? extends VectorStep> c)
Overrides ArrayList method.

Specified by:
addAll in interface java.util.Collection<VectorStep>
Specified by:
addAll in interface java.util.List<VectorStep>
Overrides:
addAll in class java.util.ArrayList<VectorStep>
Parameters:
c - the collection to add
Returns:
true if at least one item in the collection is successfully added

add

public void add(int index,
                VectorStep v)
Overrides ArrayList method.

Specified by:
add in interface java.util.List<VectorStep>
Overrides:
add in class java.util.ArrayList<VectorStep>
Parameters:
index - the index
v - the vector to add

remove

public VectorStep remove(int index)
Overrides ArrayList method.

Specified by:
remove in interface java.util.List<VectorStep>
Overrides:
remove in class java.util.ArrayList<VectorStep>
Parameters:
index - the index
Returns:
the object removed

remove

public boolean remove(java.lang.Object obj)
Overrides ArrayList method.

Specified by:
remove in interface java.util.Collection<VectorStep>
Specified by:
remove in interface java.util.List<VectorStep>
Overrides:
remove in class java.util.ArrayList<VectorStep>
Parameters:
obj - the object to remove
Returns:
false

removeRange

public void removeRange(int from,
                        int to)
Overrides ArrayList method.

Overrides:
removeRange in class java.util.ArrayList<VectorStep>
Parameters:
from - index
to - index

retainAll

public boolean retainAll(java.util.Collection<?> c)
Overrides ArrayList method.

Specified by:
retainAll in interface java.util.Collection<VectorStep>
Specified by:
retainAll in interface java.util.List<VectorStep>
Overrides:
retainAll in class java.util.AbstractCollection<VectorStep>
Parameters:
c - a collection
Returns:
false

addAll

public boolean addAll(int index,
                      java.util.Collection<? extends VectorStep> c)
Overrides ArrayList method.

Specified by:
addAll in interface java.util.List<VectorStep>
Overrides:
addAll in class java.util.ArrayList<VectorStep>
Parameters:
index - the index
c - the collection to add
Returns:
true if the collection is successfully added

set

public VectorStep set(int index,
                      VectorStep obj)
Overrides ArrayList method.

Specified by:
set in interface java.util.List<VectorStep>
Overrides:
set in class java.util.ArrayList<VectorStep>
Parameters:
index - the index
obj - the object
Returns:
the element previously at index

isAllowed

protected boolean isAllowed(VectorStep vector)
Determines whether the specified vector is allowed to be added to the end hinge.

Parameters:
vector - the vector
Returns:
true if allowed

remove

protected java.util.ArrayList<VectorStep> remove(VectorStep vector)
Removes vectors downstream of and including the specified vector.

Parameters:
vector - the vector
Returns:
the list of vectors removed