Class EnhancedVector
- All Implemented Interfaces:
Serializable, Cloneable, Comparable<EnhancedVector>, Iterable<Integer>, Collection<Integer>, List<Integer>, RandomAccess, SequencedCollection<Integer>
- Direct Known Subclasses:
MultiplicitiesVector, PopulationChangeVector, PopulationVector
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:
-
Field Summary
Fields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty EnhancedVector object.EnhancedVector(int[] A) Creates an EnhancedVector with content equal to the given matrix.EnhancedVector(int k, int length) Creates a new EnhancedVector of specific lenth, where all elements are equal to a specific value.EnhancedVector(Integer[] A) Creates an EnhancedVector with content equal to the given matrix. -
Method Summary
Modifier and TypeMethodDescriptionAdds two vectors.intCompares two EnhancedVector objects according to the sum of their elements.booleanChecks whether a value of -1 is contained in the EnhancedVector.copy()This method returns a copy of the current EnhancedVector object.protected voidcopyTo(EnhancedVector destination) This method copies the current EnhancedVector to a new one.intintThis method is used to count the elements of the EnhancedVvector that are equal to zero.booleanThis 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.protected voidfillFromMyVector(EnhancedVector source) This method copies a source EnhancedVector to the current one.intThis method returns the index of the first non-zero EnhancedVector element.getAsBigRational(int index) Returns the number in a specific index of the EnhancedVector as a BigRational object.booleanbooleanThis method decides whether all elements of the EnhancedVector are equal to zero (hence, a zero vector).intmax()This method returns the maximum element of an EnhancedVectorintmin()This method returns the minimum element of an EnhancedVectorvoidminusOne(int s) This method dereases the element at a position by 1.voidplusOne(int k) This method increases the element at a position by 1.voidprint()voidrestore()This method restores the last alteration made to the EnhancedVector.intsum()This method returns the sum of all EnhancedVector elements.Methods inherited from class ArrayList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class AbstractCollection
containsAll, toStringMethods inherited from interface Collection
parallelStream, stream, toArrayMethods inherited from interface List
containsAll, reversed
-
Constructor Details
-
EnhancedVector
public EnhancedVector()Creates an empty EnhancedVector object. -
EnhancedVector
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 elementslength- 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
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
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
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
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
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
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
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
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:
compareToin interfaceComparable<EnhancedVector>- Parameters:
o- The other EnhancedVector object- Returns:
- -1 if this < o, 0 if this = o, 1 if this > o
-
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
Adds two vectors. The vectors must be of the same size.- Parameters:
b- Vector to add- Returns:
- The result of the addition
-
subVec
- 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.
-