Remove redundant gets and puts to the cells map

This commit is contained in:
Alex Birkett 2016-01-30 13:20:56 +01:00
parent bf40cf0735
commit 6543ad07b7
1 changed files with 8 additions and 21 deletions

View File

@ -70,29 +70,16 @@ public class Row {
* is zero, the symbol will be removed from the row
*/
void insert(Symbol symbol, double coefficient) {
Double existingCoefficient = cells.get(symbol);
//this looks different than c++ code
// Double existingCoefficient = cells.get(symbol);
//
// 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);
if (existingCoefficient != null) {
coefficient += existingCoefficient;
}
double temp = this.cells.get(symbol) + coefficient;
this.cells.put(symbol, temp);
if(Util.nearZero(temp)){
this.cells.remove(symbol);
if (Util.nearZero(coefficient)) {
cells.remove(symbol);
} else {
cells.put(symbol, Double.valueOf(coefficient));
}
}