source: src/main/java/agents/anac/y2014/AgentYK/PairBidElementHistory.java@ 345

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

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package agents.anac.y2014.AgentYK;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6
7
8public class PairBidElementHistory {
9 List<PairBidElementDetails> pairBidElements;
10 HashMap<String, Integer> countMap;
11 HashMap<String, Double> weightedCountMap;
12
13 public PairBidElementHistory() {
14 this.pairBidElements = new ArrayList<PairBidElementDetails>();
15 countMap = new HashMap<String, Integer>();
16 weightedCountMap = new HashMap<String, Double>();
17 }
18
19 public PairBidElementHistory(List<PairBidElementDetails> pairBidElements) {
20 for(PairBidElementDetails pbe:pairBidElements) {
21 this.pairBidElements.add(pbe);
22 }
23 countMap = new HashMap<String, Integer>();
24 weightedCountMap = new HashMap<String, Double>();
25 }
26
27 public void add(PairBidElementDetails pbed) {
28 this.pairBidElements.add(pbed);
29 if(this.countMap.containsKey(pbed.getPairBidElement().toString())) {
30 int value = this.countMap.get(pbed.getPairBidElement().toString()) + 1;
31 this.countMap.put(pbed.getPairBidElement().toString(), value);
32 } else {
33 this.countMap.put(pbed.getPairBidElement().toString(), 1);
34 }
35
36 if(this.weightedCountMap.containsKey(pbed.getPairBidElement().toString())) {
37 double value = this.weightedCountMap.get(pbed.getPairBidElement().toString()) + pbed.getTime()*pbed.getTime();
38 this.weightedCountMap.put(pbed.getPairBidElement().toString(), value);
39 } else {
40 this.weightedCountMap.put(pbed.getPairBidElement().toString(), pbed.getTime()*pbed.getTime());
41 }
42 }
43
44 public List<PairBidElementDetails> getHistory() {
45 return this.pairBidElements;
46 }
47
48 public PairBidElementHistory filterBetweenTime(double t1, double t2) {
49 PairBidElementHistory pbeh = new PairBidElementHistory();
50 for(PairBidElementDetails pbed:this.pairBidElements) {
51 if(t1 < pbed.getTime() && pbed.getTime() <= t2) pbeh.add(pbed);
52 }
53 return pbeh;
54 }
55
56 public int getAppearanceCount(PairBidElement pairBidElement) {
57 if(this.countMap.containsKey(pairBidElement.toString())) {
58 return this.countMap.get(pairBidElement.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(PairBidElement pairBidElement) {
72 if(this.weightedCountMap.containsKey(pairBidElement.toString())) {
73 return this.weightedCountMap.get(pairBidElement.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 pairBidElements.size();
88 }
89}
Note: See TracBrowser for help on using the repository browser.