Skip to content

Commit b9f5e33

Browse files
committed
More correct iteration
1 parent 9c5e61b commit b9f5e33

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/jama2/Matrix.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ public static Matrix read(final BufferedReader input) throws IOException
228228
tokenizer.wordChars(0, 255);
229229
tokenizer.whitespaceChars(0, ' ');
230230
tokenizer.eolIsSignificant(true);
231-
final Vector<Double> vD = new Vector<>();
232231

233232
while (tokenizer.nextToken() == StreamTokenizer.TT_EOL)
234233
{
@@ -240,30 +239,32 @@ public static Matrix read(final BufferedReader input) throws IOException
240239
throw new IOException("Unexpected EOF on matrix read."); //$NON-NLS-1$
241240
}
242241

242+
final Vector<Double> vD = new Vector<>();
243243
do
244244
{
245245
// Read & store 1st row.
246-
vD.addElement(Double.valueOf(tokenizer.sval));
246+
vD.addElement(new Double(tokenizer.sval));
247247
}
248248
while (tokenizer.nextToken() == StreamTokenizer.TT_WORD);
249249

250250
// Now we've got the number of columns!
251251
final int n = vD.size();
252252
double row[] = new double[n];
253-
for (int j = 0; j < n; j++)
253+
int j = 0;
254+
for (final Double d : vD)
254255
{
255256
// extract the elements of the 1st row.
256-
row[j] = vD.elementAt(j).doubleValue();
257+
row[j++] = d.doubleValue();
257258
}
258-
final Vector<double[]> v = new Vector<>();
259259

260260
// Start storing rows instead of columns.
261+
final Vector<double[]> v = new Vector<>();
261262
v.addElement(row);
262263
while (tokenizer.nextToken() == StreamTokenizer.TT_WORD)
263264
{
264265
// While non-empty lines
265266
v.addElement(row = new double[n]);
266-
int j = 0;
267+
j = 0;
267268
do
268269
{
269270
if (j >= n)
@@ -654,6 +655,13 @@ public boolean equals(final Matrix other)
654655
return (other == this) || ((other != null) && ((this.m == other.m) && (this.n == other.n) && Arrays.deepEquals(this.A, other.A)));
655656
}
656657

658+
/**
659+
* Overloads
660+
*
661+
* @param obj
662+
* another object
663+
* @return true if other equals A
664+
*/
657665
@Override
658666
public boolean equals(final Object obj)
659667
{

0 commit comments

Comments
 (0)