Class EnhancedVector

All Implemented Interfaces:
Serializable, Cloneable, Comparable<EnhancedVector>, Iterable<Integer>, Collection<Integer>, List<Integer>, RandomAccess, SequencedCollection<Integer>
Direct Known Subclasses:
MultiplicitiesVector, PopulationChangeVector, PopulationVector

public class EnhancedVector extends ArrayList<Integer> implements Comparable<EnhancedVector>
This class extends the ArrayList<Integer> object class by adding several useful methods for operations encountered when dealing with the algorithms that compute the normalising constants.
Author:
Michail Makaronidis, 2010,, amended by Jack Bradshaw 2012. Amendments: No longer implements comparable, to allow subclasses to do so
See Also:
  • Constructor Details

    • EnhancedVector

      public EnhancedVector()
      Creates an empty EnhancedVector object.
    • EnhancedVector

      public EnhancedVector(Integer[] A)
      Creates an EnhancedVector with content equal to the given matrix.
      Parameters:
      A - The matrix containing the vector elements
    • EnhancedVector

      public EnhancedVector(int[] A)
      Creates an EnhancedVector with content equal to the given matrix.
      Parameters:
      A - The matrix containing the vector elements
    • EnhancedVector

      public EnhancedVector(int k, int length)
      Creates a new EnhancedVector of specific lenth, where all elements are equal to a specific value.
      Parameters:
      k - The value of all elements
      length - The length of the EnhancedVector
  • Method Details

    • isZeroVector

      public boolean isZeroVector()
      This method decides whether all elements of the EnhancedVector are equal to zero (hence, a zero vector).
      Returns:
      True if it is a zero vector, false otherwise
    • containsMinusOne

      public boolean containsMinusOne()
      Checks whether a value of -1 is contained in the EnhancedVector.
      Returns:
      True if -1 is contained, else false.
    • findFirstNonZeroElement

      public int findFirstNonZeroElement() throws InternalErrorException
      This method returns the index of the first non-zero EnhancedVector element. Throws exception when used on a zero vector.
      Returns:
      The index of the first non-zero EnhancedVector element
      Throws:
      InternalErrorException - Thrown when used on a zero vector
    • getAsBigRational

      public BigRational getAsBigRational(int index)
      Returns the number in a specific index of the EnhancedVector as a BigRational object.
      Parameters:
      index - The position's index
      Returns:
      The number in that position as a BigRational
    • sum

      public int sum()
      This method returns the sum of all EnhancedVector elements.
      Returns:
      The sum
    • minusOne

      public void minusOne(int s)
      This method dereases the element at a position by 1.
      Parameters:
      s - The index of the position (starts from 1)
    • plusOne

      public void plusOne(int k)
      This method increases the element at a position by 1.
      Parameters:
      k - The index of the position (starts from 1)
    • restore

      public void restore()
      This method restores the last alteration made to the EnhancedVector. If no alteration has been made, the method terminates silently.
    • countZeroElements

      public int countZeroElements()
      This method is used to count the elements of the EnhancedVvector that are equal to zero.
      Returns:
      The number of zero elements
    • copyTo

      protected void copyTo(EnhancedVector destination)
      This method copies the current EnhancedVector to a new one. Position and delta stacks are disregarded.
      Parameters:
      destination - The EnhancedVector to which the current one is copied
    • fillFromMyVector

      protected void fillFromMyVector(EnhancedVector source)
      This method copies a source EnhancedVector to the current one. Position and delta stacks are disregarded.
      Parameters:
      source - The EnhancedVector from which the elements are copied
    • max

      public int max() throws OperationNotSupportedException
      This method returns the maximum element of an EnhancedVector
      Returns:
      The maximum element
      Throws:
      OperationNotSupportedException - Thrown when evaluation of the maximum element is requested on an empty vector
    • min

      public int min() throws OperationNotSupportedException
      This method returns the minimum element of an EnhancedVector
      Returns:
      The minimum element
      Throws:
      OperationNotSupportedException - Thrown when evaluation of the minimum element is requested on an empty vector
    • equalsIgnoreHistory

      public boolean equalsIgnoreHistory(Object o)
      This method is like the equals() method, with the only diferrence that it only check the elements of the EnhancedVectors and does not consider the previous alterations held in the two stacks.
      Parameters:
      o - The object to which
      Returns:
    • compareTo

      public int compareTo(EnhancedVector o)
      Compares two EnhancedVector objects according to the sum of their elements. elements. If they have the same sum, then the one with the leftmost non-zero is the smaller.
      Specified by:
      compareTo in interface Comparable<EnhancedVector>
      Parameters:
      o - The other EnhancedVector object
      Returns:
      -1 if this < o, 0 if this = o, 1 if this > o
    • copy

      public EnhancedVector copy()
      This method returns a copy of the current EnhancedVector object. Position and delta stacks are disregarded.
      Returns:
      Copy of the initial EnhancedVector object.
    • addVec

      public EnhancedVector addVec(EnhancedVector b)
      Adds two vectors. The vectors must be of the same size.
      Parameters:
      b - Vector to add
      Returns:
      The result of the addition
    • subVec

      public EnhancedVector subVec(EnhancedVector b)
      Parameters:
      b - Vector to add
      Returns:
      The result of the subtraction
    • print

      public void print()
    • countNonZeroElements

      public int countNonZeroElements()
      Returns:
      The number of non-zero elements
    • isOneVector

      public boolean isOneVector()
      Returns:
      whether the vector contains all ones.