Skip to content

Commit

Permalink
Merge pull request #75 from arup-group/potential-performance
Browse files Browse the repository at this point in the history
Performance with TableSaw
  • Loading branch information
mfitz authored May 1, 2024
2 parents cfc5639 + 29e72b9 commit b96ed09
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 183 deletions.
20 changes: 8 additions & 12 deletions src/main/java/com/arup/cml/abm/kpi/data/MoneyLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
import java.util.*;

public class MoneyLog {
HashMap<String, HashMap<Double, Double>> moneyLogData = new HashMap<>();

public HashMap<String, HashMap<Double, Double>> getMoneyLogData() {
Map<String, Map<Double, Double>> moneyLogData = new HashMap<>();

public Map<String, Map<Double, Double>> getMoneyLogData() {
return moneyLogData;
}

public HashMap<Double, Double> getMoneyLogData(String personID) {
public Map<Double, Double> getMoneyLogData(String personID) {
return getPersonLog(personID);
}

public void createMoneyLogEntry(String personID, double time, double amount) {
HashMap<Double, Double> personLog = getPersonLog(personID);
if (personLog.containsKey(time)) {
personLog.put(time, amount + personLog.get(time));
} else {
personLog.put(time, amount);
}
Map<Double, Double> personLog = getPersonLog(personID);
personLog.compute(time, (k, v) -> (v == null) ? amount : amount + v);
}

private HashMap<Double, Double> getPersonLog(String personID) {
moneyLogData.putIfAbsent(personID, new HashMap<>());
return moneyLogData.get(personID);
private Map<Double, Double> getPersonLog(String personID) {
return moneyLogData.computeIfAbsent(personID, k -> new HashMap<>());
}

}
Loading

0 comments on commit b96ed09

Please sign in to comment.