Skip to main content
added 12 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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@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 addMatrixaddMatrix() function, it looks like you are making some confusing/improper assignments:

    `this this.doubMatrix = doubMatrix`doubMatrix
    

    ...is overwriting your current DoubleMatrix backing array with the one you are passing into the method (the this keyword refers to the class' scope, not the method's scope). I would suggest simply renaming the addMatrixaddMatrix() parameter to something else so you don't have the confusion of working with this.doubMatrix and doubMatrix.

  • Your addMatrixaddMatrix() result array (tempArray) is also initialized to null and never properly initialized before you start placing values there. That's going to throw a NullPointerException.

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 DoubleMatrix backing array with the one you are passing into the method (the this keyword 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 with this.doubMatrix and doubMatrix.

  • Your addMatrix result array (tempArray) is also initialized to null and never properly initialized before you start placing values there. That's going to throw a NullPointerException.

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 DoubleMatrix backing array with the one you are passing into the method (the this keyword 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 with this.doubMatrix and doubMatrix.

  • Your addMatrix() result array (tempArray) is also initialized to null and never properly initialized before you start placing values there. That's going to throw a NullPointerException.

Source Link
Eric P.
  • 581
  • 2
  • 6

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 DoubleMatrix backing array with the one you are passing into the method (the this keyword 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 with this.doubMatrix and doubMatrix.

  • Your addMatrix result array (tempArray) is also initialized to null and never properly initialized before you start placing values there. That's going to throw a NullPointerException.