jv.vecmath

Class PbVector

• All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class PbVector
extends P_Vector
implements java.lang.Cloneable
Linear algebra class for an array of booleans with variable length.
Serialized Form
• Field Summary

Fields
Modifier and Type Field and Description
boolean[] m_data
Data array containing the components of the vector.
• Constructor Summary

Constructors
Constructor and Description
PbVector()
Construct vector with zero size.
PbVector(boolean x)
Constructs a vector of length 1 and given initial data.
PbVector(boolean[] x)
Constructs a vector having same length and given initial data as given array.
PbVector(boolean x, boolean y)
Constructs a vector of length 2 and given initial data.
PbVector(boolean x, boolean y, boolean z)
Constructs a vector of length 3 and given initial data.
PbVector(boolean x, boolean y, boolean z, boolean w)
Constructs a vector of length 4 and given initial data.
PbVector(int aSize)
Constructor creating a vector with given dimension.
• Method Summary

Methods
Modifier and Type Method and Description
Add another entry at the end of the vector and increment size of vector.
static PbVector[][] alloc(int sizeI, int sizeJ, int vectorSize)
Allocate a new array of vectors, where all vectors have the same dimension.
void and(PbVector v)
Apply the 'AND' operation component-wise to the entries of this and v and store the results in this.
void blend(double a, PbVector v, double b, PbVector w)
Interpolate between two vectors with given weights.
static PbVector blendNew(double a, PbVector v, double b, PbVector w)
Create a new vector this = a*v + b*w.
java.lang.Object clone()
Clone object and all instance variables.
void copy(boolean[] anArray, int aSize)
Copy a boolean array into a vector, and do not adjust size of dest vector.
void copy(boolean[] anArray, int srcPos, int aSize)
Copy part of a boolean array into a vector, and do not adjust size of dest vector.
boolean copy(int destInd, PbVector dataSrc, int srcInd, int size)
Copy part of the source vector into this vector, and adjust size of this vector only if it is too small.
void copy(PbVector v)
Copy a vector into a vector, and do not adjust size of dest vector.
static boolean copy(PbVector[] dataDest, int destInd, PbVector[] dataSrc, int srcInd, int size)
Copies some vectors of a given array of vectors into an existing destination array.
void copyArray(PbVector v)
Copy data array of source vector into this vector, and do not adjust size of dest vector.
static PbVector[] copyNew(boolean[][] data)
Create an new array with copies of all booleans of a given 2-dimensional array of numbers.
static PbVector copyNew(PbVector v)
Create a new vector as clone of argument vector.
static PbVector[] copyNew(PbVector[] data)
Create an new array with copies of all vectors of a given array of vectors.
static PbVector[] copyNew(PbVector[] data, int size)
Create an new array with copies of the first 'size' vectors of a given array of vectors.
int countTrueEntries()
Count number of entries with state = true.
int countValue(boolean b)
Count the entries that have the same value as b.
boolean equals(boolean[] list)
Compare vector with list of booleans and return false if different array lengths or a different entry.
boolean equals(java.lang.Object obj)
Determines whether another vector or array of booleans is equal to this vector.
boolean equals(PbVector v)
Determines whether another vector is equal to this vector.
boolean[] getEntries()
Return a copy of the content of vector as array of booleans.
static boolean[][] getEntries(PbVector[] vArr)
Return content of array of vectors as matrix of boolean.
boolean getEntry(int ind)
Get the component of a vector.
boolean getFirstEntry()
Get the first component of a vector.
boolean getLastEntry()
Get the last component of a vector.
static int getSameSize(PbVector[] vecArray, int numUsed)
Check of all vectors in array of vector have same length.
int getSize()
Get dimension of vector, i.e. length of its data array.
int indexOf(boolean value)
Computes the index i of the first entry of vector with v[i]==value.
void invert()
Invert order of all entries, i.e. the first entry becomes the last entry.
void invert(int usedSize)
Invert order of the first 'usedSize' entries, i.e. the first entry becomes the 'usedSize-1' entry.
void invertEntries()
Set all entries e to (not e).
void or(PbVector v)
Apply the 'OR' operation component-wise to the entries of this and v and store the results in this.
static PbVector[] realloc(PbVector[] data, int arraySize)
Allocate an array of vectors.
static PbVector[] realloc(PbVector[] data, int arraySize, int vectorSize)
Allocate an array of vectors, where all vectors have the same dimension.
void set(boolean x)
Assign value to vector, and increase size of vector if necessary.
void set(boolean[] x)
Assign values of boolean array to vector, and adjust length of vector if different from length of array.
void set(boolean[] x, int len)
Assign first values of boolean array to vector, and adjust length of vector if different from argument len.
void set(boolean[] x, int from, int len)
Assign 'len' values of boolean array starting at 'from' to vector, and adjust length of vector if different from argument len.
void set(boolean x, boolean y)
Assign value to vector, and increase size of vector if necessary.
void set(boolean x, boolean y, boolean z)
Assign value to vector, and increase size of vector if necessary.
void set(boolean x, boolean y, boolean z, boolean w)
Assign value to vector, and increase size of vector if necessary.
void set(PbVector x, int from, int len)
Assign 'len' values of array starting at 'from' to vector, and adjust length of vector if different from argument len.
void setConstant(boolean aValue)
Set all entries to a constant value.
static void setConstant(boolean[] v, boolean aValue)
Set all entries to a constant value.
static void setConstant(PbVector[] vecArr, boolean aValue)
Set all components of all vectors of an array to a constant.
static void setConstant(PbVector[] vecArr, boolean[] data)
Set all vectors of an array equal to a given vector.
static void setConstant(PbVector[] vecArr, PbVector aVector)
Set all vectors of an array equal to a given vector.
static void setConstant(PbVector v, boolean aValue)
Set all entries to a constant value.
void setEntry(int ind, boolean value)
Assign value to component of vector, and possibly enlarge vector if too small.
void setFirstEntry(boolean value)
Set the first component of a vector.
void setLastEntry(boolean value)
Set the last component of a vector.
int setSize(int aSize)
Set dimension of vector, i.e. length of its data array.
java.lang.String toShortString()
Create a single-line string representation of the vector components and attributes.
java.lang.String toString()
Create a multi-line string representation of the vector with detailed information about all instance variables.
void xor(PbVector v)
Apply the 'XOR' operation component-wise to the entries of this and v and store the results in this.
• Methods inherited from class java.lang.Object

getClass, hashCode, notify, notifyAll, wait, wait, wait
• Field Detail

• m_data

public boolean[] m_data
Data array containing the components of the vector. Array has public access for efficiency reasons in numerical computations, although method access should be preferred. Do not modify length of array directly.
• Constructor Detail

• PbVector

public PbVector()
Construct vector with zero size.
• PbVector

public PbVector(int aSize)
Constructor creating a vector with given dimension.
• PbVector

public PbVector(boolean x)
Constructs a vector of length 1 and given initial data.
• PbVector

public PbVector(boolean x,
boolean y)
Constructs a vector of length 2 and given initial data.
• PbVector

public PbVector(boolean x,
boolean y,
boolean z)
Constructs a vector of length 3 and given initial data.
• PbVector

public PbVector(boolean x,
boolean y,
boolean z,
boolean w)
Constructs a vector of length 4 and given initial data.
• PbVector

public PbVector(boolean[] x)
Constructs a vector having same length and given initial data as given array.
• Method Detail

• clone

public java.lang.Object clone()
Clone object and all instance variables. Similar like copyNew(PbVector) but this clone() method is consistent with possible subclasses while copyNew() explicitly creates a new PbVector.
Overrides:
clone in class java.lang.Object
copyNew(PbVector)
• getEntries

public static boolean[][] getEntries(PbVector[] vArr)
Return content of array of vectors as matrix of boolean.
Parameters:
vArr - Array of vectors
Returns:
2-dimensional matrix of boolean
• alloc

public static PbVector[][] alloc(int sizeI,
int sizeJ,
int vectorSize)
Allocate a new array of vectors, where all vectors have the same dimension.
Parameters:
sizeI - number of rows in new array
sizeJ - number of columns in row[i] in new array
vectorSize - dimension of vectors in new array
• realloc

public static PbVector[] realloc(PbVector[] data,
int arraySize,
int vectorSize)
Allocate an array of vectors, where all vectors have the same dimension. If argument data!=null then as most as possible of the content of existing vectors is copied into (possibly reused) vectors of the reallocated array.

If requested array size is 0 then method returns an array of length 0.

Parameters:
data - possibly empty array of vectors
arraySize - number of vectors in new array
vectorSize - dimension of vectors in new array
• realloc

public static PbVector[] realloc(PbVector[] data,
int arraySize)
Allocate an array of vectors. If argument data!=null then as most as possible of the existing vectors are reused in the reallocated array. New vectors are allocated with dimension zero.

If requested array size is 0 then method returns an array of length 0.

Parameters:
data - possibly empty array of vectors
arraySize - number of vectors in new array
• copyNew

public static PbVector[] copyNew(boolean[][] data)
Create an new array with copies of all booleans of a given 2-dimensional array of numbers. Each row of argument vector is stored in a vector. Rows may have different length. A row with length zero leads to a warning message, and allocates a vector with length zero.
Parameters:
data - 2-dimensional array of numbers
Returns:
new array with same number of vectors as rows of argument array
• copyNew

public static PbVector[] copyNew(PbVector[] data)
Create an new array with copies of all vectors of a given array of vectors. The new array contains new vectors containing the same data as the original vectors.
Parameters:
data - array of vectors
Returns:
new array with same number of vectors as argument array
• copyNew

public static PbVector[] copyNew(PbVector[] data,
int size)
Create an new array with copies of the first 'size' vectors of a given array of vectors. The new array contains new vectors containing the same data as the original vectors.
Parameters:
data - array of vectors
size - number of copied vectors of array
Returns:
new array with number of vectors equal to argument 'size'
copyNew(PbVector [])
• copy

int destInd,
PbVector[] dataSrc,
int srcInd,
int size)
Copies some vectors of a given array of vectors into an existing destination array. All vectors in source and destination array must exist already.
for (int i=0; i
Destination array must be large enough, i.e. dataDest.length >= destInd+size.
Parameters:
dataDest - destination array of vectors
destInd - index of first destination vector in dataDest
dataSrc - source array of vectors
srcInd - index of first source vector in dataSrc used for copying
size - number of copied vectors of array
Returns:
true if destination array is large enough
copy(PbVector)
• getSameSize

public static int getSameSize(PbVector[] vecArray,
int numUsed)
Check of all vectors in array of vector have same length.
Returns:
same length, or -1 if different or no entries.
• setConstant

public static void setConstant(PbVector[] vecArr,
boolean aValue)
Set all components of all vectors of an array to a constant.
• setConstant

public static void setConstant(PbVector[] vecArr,
boolean[] data)
Set all vectors of an array equal to a given vector. All vectors of argument array must have same length.
• setConstant

public static void setConstant(PbVector[] vecArr,
PbVector aVector)
Set all vectors of an array equal to a given vector. All vectors of argument array must have same length.
• setConstant

public static void setConstant(PbVector v,
boolean aValue)
Set all entries to a constant value.
• setConstant

public static void setConstant(boolean[] v,
boolean aValue)
Set all entries to a constant value.
• setConstant

public void setConstant(boolean aValue)
Set all entries to a constant value.
• getSize

public int getSize()
Get dimension of vector, i.e. length of its data array.
• setSize

public int setSize(int aSize)
Set dimension of vector, i.e. length of its data array.
Parameters:
aSize - new number of components of vector
Returns:
new number of components of vector
• getEntries

public boolean[] getEntries()
Return a copy of the content of vector as array of booleans.
• getEntry

public boolean getEntry(int ind)
Get the component of a vector.
• setEntry

public void setEntry(int ind,
boolean value)
Assign value to component of vector, and possibly enlarge vector if too small.
Parameters:
ind - index of component.
value - new value of component.
• getFirstEntry

public boolean getFirstEntry()
Get the first component of a vector.
Returns:
value of the first component.
• setFirstEntry

public void setFirstEntry(boolean value)
Set the first component of a vector.
Parameters:
value - new value of first component
• getLastEntry

public boolean getLastEntry()
Get the last component of a vector.
Returns:
value of the last component.
• setLastEntry

public void setLastEntry(boolean value)
Set the last component of a vector.
Parameters:
value - new value of last component

Add another entry at the end of the vector and increment size of vector.
Parameters:
val - value to be added
Returns:
index of new last entry.
• set

public void set(PbVector x,
int from,
int len)
Assign 'len' values of array starting at 'from' to vector, and adjust length of vector if different from argument len.
• set

public void set(boolean[] x,
int from,
int len)
Assign 'len' values of boolean array starting at 'from' to vector, and adjust length of vector if different from argument len.
• set

public void set(boolean[] x,
int len)
Assign first values of boolean array to vector, and adjust length of vector if different from argument len.
• set

public void set(boolean[] x)
Assign values of boolean array to vector, and adjust length of vector if different from length of array.
• set

public void set(boolean x)
Assign value to vector, and increase size of vector if necessary.
• set

public void set(boolean x,
boolean y)
Assign value to vector, and increase size of vector if necessary.
• set

public void set(boolean x,
boolean y,
boolean z)
Assign value to vector, and increase size of vector if necessary.
• set

public void set(boolean x,
boolean y,
boolean z,
boolean w)
Assign value to vector, and increase size of vector if necessary.
• invert

public void invert(int usedSize)
Invert order of the first 'usedSize' entries, i.e. the first entry becomes the 'usedSize-1' entry.
invert()
• invert

public void invert()
Invert order of all entries, i.e. the first entry becomes the last entry.
invert(int)
• invertEntries

public void invertEntries()
Set all entries e to (not e).
• and

public void and(PbVector v)
Apply the 'AND' operation component-wise to the entries of this and v and store the results in this.
• or

public void or(PbVector v)
Apply the 'OR' operation component-wise to the entries of this and v and store the results in this.
• xor

public void xor(PbVector v)
Apply the 'XOR' operation component-wise to the entries of this and v and store the results in this.
• countValue

public int countValue(boolean b)
Count the entries that have the same value as b.
• copyNew

public static PbVector copyNew(PbVector v)
Create a new vector as clone of argument vector.
Parameters:
v - source vector to clone
• copy

public boolean copy(int destInd,
PbVector dataSrc,
int srcInd,
int size)
Copy part of the source vector into this vector, and adjust size of this vector only if it is too small.
copy(PbVector)
• copy

public void copy(PbVector v)
Copy a vector into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source vector. If source and destination vectors have different size then use the mininum of both sizes. If destination vector is bigger than source then reset the additional entries in destination vector with 0.
Parameters:
v - source vector to copy
copy(int,PbVector,int,int)
• copyArray

public void copyArray(PbVector v)
Copy data array of source vector into this vector, and do not adjust size of dest vector. In contrast to copy(PbVector) this method does not invoke the copy method of the superclass. If destination vector is empty then allocated space of size of source vector. If source and destination vectors have different size then use the mininum of both sizes for copying. If destination vector is bigger than source then reset the additional entries in destination vector with 0.
Parameters:
v - source vector to copy
copy(PbVector)
• copy

public void copy(boolean[] anArray,
int aSize)
Copy a boolean array into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source array. If source and destination vectors have different size then use the mininum of both sizes. If destination vector is bigger than source then reset the additional entries in destination vector with 0.
copy(int,PbVector,int,int)
• copy

public void copy(boolean[] anArray,
int srcPos,
int aSize)
Copy part of a boolean array into a vector, and do not adjust size of dest vector. If destination vector is empty then allocated space of size of source array. If parameter size and length of destination vectors are different then use the minimum of both sizes. If destination vector is bigger than argument size then reset the additional entries in destination vector with 0.
Parameters:
anArray - array of booleans
srcPos - first position in array used for copying
aSize - number of entries to copy.
• countTrueEntries

public int countTrueEntries()
Count number of entries with state = true.
• blend

public void blend(double a,
PbVector v,
double b,
PbVector w)
Interpolate between two vectors with given weights. Uses this = v, if a>=b, or this = w, else. If result vector 'this' is empty then its size is set to length of vector v, otherwise interpolation is done up to length of result vector.
Parameters:
a - weight of first vector
v - first vector
b - weight of second vector
w - second vector
blendNew(double, PbVector, double, PbVector)
• indexOf

public int indexOf(boolean value)
Computes the index i of the first entry of vector with v[i]==value.
Returns:
Index of the first entry of vector with v[i]==value or -1 if value is smaller than minimum value of vector.
• equals

public boolean equals(boolean[] list)
Compare vector with list of booleans and return false if different array lengths or a different entry. Determines whether a list of booleans is equal to data of this vector. The result is true if both arrays have same length and equal components. Result is also true if argument vector is null and this vector has no entries.
Parameters:
list - the list of booleans to compare with
Returns:
true if the objects are the same; false otherwise.
• equals

public boolean equals(java.lang.Object obj)
Determines whether another vector or array of booleans is equal to this vector.
Overrides:
equals in class java.lang.Object
Since:
JavaView 3.62.012
equals(boolean[]), equals(PbVector), Object.equals(java.lang.Object)
• equals

public boolean equals(PbVector v)
Determines whether another vector is equal to this vector. The result is true if both vectors have same length and equal components. Result is also true if argument vector is null and this vector has no entries.
Parameters:
v - the vector to compare with
Returns:
true if the objects are the same; false otherwise.
• toString

public java.lang.String toString()
Create a multi-line string representation of the vector with detailed information about all instance variables.
Overrides:
toString in class P_Vector