For clarity, I would combine the size check conditional, and further, move it to it's own method to make the code a bit more clear. Working with objects (as Alex suggested), will make this much easier:
if(this.doubMatrix.length == doubMatrix.length)
if(this.doubMatrix[0].length == doubMatrix[0].length) {
// stuff
}
Change to something like:
if(this.isSameSize(doubMatrix))
{
//stuff
}
// ...
// later
public boolean isSameSize(DoubleMatrix doub) {
return // Comparison of column and rows of backing arrays
}
Also in your addMatrix function, it looks like you are making some confusing/improper assignments:
`this.doubMatrix = doubMatrix`...is overwriting your current
DoubleMatrixbacking array with the one you are passing into the method (thethiskeyword refers to the class' scope, not the method's scope). I would suggest simply renaming the addMatrix parameter to something else so you don't have the confusion of working withthis.doubMatrixanddoubMatrix.Your addMatrix result array (
tempArray) is also initialized tonulland never properly initialized before you start placing values there. That's going to throw aNullPointerException.