source: src/main/java/agents/anac/y2014/AgentYK/BidElementHistory.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.4 KB
RevLine 
[1]1package agents.anac.y2014.AgentYK;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6
7
8public class BidElementHistory {
9 List<BidElementDetails> bidElements;
10 HashMap<String, Integer> countMap;
11 HashMap<String, Double> weightedCountMap;
12
13 public BidElementHistory() {
14 this.bidElements = new ArrayList<BidElementDetails>();
15 countMap = new HashMap<String, Integer>();
16 weightedCountMap = new HashMap<String, Double>();
17 }
18
19 public BidElementHistory(List<BidElementDetails> bidElements) {
20 for(BidElementDetails bed:bidElements) {
21 this.bidElements.add(bed);
22 }
23 countMap = new HashMap<String, Integer>();
24 weightedCountMap = new HashMap<String, Double>();
25 }
26
27 public void add(BidElementDetails bed) {
28 this.bidElements.add(bed);
29 if(this.countMap.containsKey(bed.getBidElement().toString())) {
30 int value = this.countMap.get(bed.getBidElement().toString()) + 1;
31 this.countMap.put(bed.getBidElement().toString(), value);
32 } else {
33 this.countMap.put(bed.getBidElement().toString(), 1);
34 }
35
36 if(this.weightedCountMap.containsKey(bed.getBidElement().toString())) {
37 double value = this.weightedCountMap.get(bed.getBidElement().toString()) + bed.getTime()*bed.getTime();
38 this.weightedCountMap.put(bed.getBidElement().toString(), value);
39 } else {
40 this.weightedCountMap.put(bed.getBidElement().toString(), bed.getTime()*bed.getTime());
41 }
42 }
43
44 public List<BidElementDetails> getHistory() {
45 return this.bidElements;
46 }
47
48 public BidElementHistory filterBetweenTime(double t1, double t2) {
49 BidElementHistory beh = new BidElementHistory();
50 for(BidElementDetails bed:this.bidElements) {
51 if(t1 < bed.getTime() && bed.getTime() <= t2) beh.add(bed);
52 }
53 return beh;
54 }
55
56 public int getAppearanceCount(BidElement bidElement) {
57 if(this.countMap.containsKey(bidElement.toString())) {
58 return this.countMap.get(bidElement.toString());
59 }
60 return 0;
61 }
62
63 public int getMaxAppearanceCount() {
64 int max = 0;
65 for(Integer i:this.countMap.values()) {
66 if(max < i) max = i;
67 }
68 return max;
69 }
70
71 public double getWeightedAppearanceCount(BidElement bidElement) {
72 if(this.weightedCountMap.containsKey(bidElement.toString())) {
73 return this.weightedCountMap.get(bidElement.toString());
74 }
75 return 0;
76 }
77
78 public double getWeightedMaxAppearanceCount() {
79 double max = 0.0;
80 for(Double i:this.weightedCountMap.values()) {
81 if(max < i) max = i;
82 }
83 return max;
84 }
85
86 public int size() {
87 return bidElements.size();
88 }
89}
Note: See TracBrowser for help on using the repository browser.