Remove redundant gets and puts to the cells map
This commit is contained in:
parent
bf40cf0735
commit
6543ad07b7
|
@ -70,29 +70,16 @@ public class Row {
|
||||||
* is zero, the symbol will be removed from the row
|
* is zero, the symbol will be removed from the row
|
||||||
*/
|
*/
|
||||||
void insert(Symbol symbol, double coefficient) {
|
void insert(Symbol symbol, double coefficient) {
|
||||||
|
Double existingCoefficient = cells.get(symbol);
|
||||||
|
|
||||||
//this looks different than c++ code
|
if (existingCoefficient != null) {
|
||||||
// Double existingCoefficient = cells.get(symbol);
|
coefficient += existingCoefficient;
|
||||||
//
|
|
||||||
// if (existingCoefficient != null) {
|
|
||||||
// coefficient = existingCoefficient;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (Util.nearZero(coefficient)) {
|
|
||||||
// cells.remove(symbol);
|
|
||||||
// } else {
|
|
||||||
// cells.put(symbol, coefficient);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//changes start here
|
|
||||||
Double value = this.cells.get(symbol);
|
|
||||||
if(value == null){
|
|
||||||
this.cells.put(symbol, 0.0);
|
|
||||||
}
|
}
|
||||||
double temp = this.cells.get(symbol) + coefficient;
|
|
||||||
this.cells.put(symbol, temp);
|
if (Util.nearZero(coefficient)) {
|
||||||
if(Util.nearZero(temp)){
|
cells.remove(symbol);
|
||||||
this.cells.remove(symbol);
|
} else {
|
||||||
|
cells.put(symbol, Double.valueOf(coefficient));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue