Class VectorChain

All Implemented Interfaces:
Serializable, Cloneable, Iterable<VectorStep>, Collection<VectorStep>, List<VectorStep>, RandomAccess

public class VectorChain extends ArrayList<VectorStep>
This is an ArrayList that represents a chain of vectors linked tip-to-tail.
Author:
Douglas Brown
See Also:
  • Constructor Details

    • 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 Details

    • 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 Collection<VectorStep>
      Specified by:
      clear in interface List<VectorStep>
      Overrides:
      clear in class ArrayList<VectorStep>
    • add

      public boolean add(VectorStep vector)
      Ads a vector to this chain.
      Specified by:
      add in interface Collection<VectorStep>
      Specified by:
      add in interface List<VectorStep>
      Overrides:
      add in class 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(Collection<? extends VectorStep> c)
      Overrides ArrayList method.
      Specified by:
      addAll in interface Collection<VectorStep>
      Specified by:
      addAll in interface List<VectorStep>
      Overrides:
      addAll in class 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 List<VectorStep>
      Overrides:
      add in class 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 List<VectorStep>
      Overrides:
      remove in class ArrayList<VectorStep>
      Parameters:
      index - the index
      Returns:
      the object removed
    • remove

      public boolean remove(Object obj)
      Overrides ArrayList method.
      Specified by:
      remove in interface Collection<VectorStep>
      Specified by:
      remove in interface List<VectorStep>
      Overrides:
      remove in class 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 ArrayList<VectorStep>
      Parameters:
      from - index
      to - index
    • retainAll

      public boolean retainAll(Collection<?> c)
      Overrides ArrayList method.
      Specified by:
      retainAll in interface Collection<VectorStep>
      Specified by:
      retainAll in interface List<VectorStep>
      Overrides:
      retainAll in class ArrayList<VectorStep>
      Parameters:
      c - a collection
      Returns:
      false
    • addAll

      public boolean addAll(int index, Collection<? extends VectorStep> c)
      Overrides ArrayList method.
      Specified by:
      addAll in interface List<VectorStep>
      Overrides:
      addAll in class 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 List<VectorStep>
      Overrides:
      set in class 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 ArrayList<VectorStep> remove(VectorStep vector)
      Removes vectors downstream of and including the specified vector.
      Parameters:
      vector - the vector
      Returns:
      the list of vectors removed