source: ai2020/group7/src/main/java/geniusweb/exampleparties/nataliaparty/DoubleMap.java

Last change on this file was 7, checked in by wouter, 4 years ago

#1925 added group7 and heavy fixes

File size: 1.1 KB
Line 
1package geniusweb.exampleparties.nataliaparty;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import geniusweb.issuevalue.Value;
7
8public class DoubleMap {
9
10 private Map<String, Map<Value, Double>> map;
11
12 public DoubleMap() {
13 this.map = new HashMap<>();
14 }
15
16 public void put(String issue, Value value, double x) {
17 Map<Value, Double> values;
18 if (map.containsKey(issue)) {
19 values = map.get(issue);
20 } else {
21 values = new HashMap<>();
22 map.put(issue, values);
23 }
24 values.put(value, x);
25 }
26
27 public double get(String issue, Value value) {
28 Map<Value, Double> values;
29 if (map.containsKey(issue)) {
30 values = map.get(issue);
31 } else {
32 return 0;
33 }
34 if (values.containsKey(value)) {
35 return values.get(value);
36 } else {
37 return 0;
38 }
39 }
40
41 public void add(String issue, Value value, double x) {
42 Map<Value, Double> values;
43 if (map.containsKey(issue)) {
44 values = map.get(issue);
45 } else {
46 values = new HashMap<>();
47 map.put(issue, values);
48 }
49 if (values.containsKey(value)) {
50 values.replace(value, values.get(value) + x);
51 } else {
52 values.put(value, x);
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.