source: trunk/autoquest-plugin-usability2/src/main/java/de/ugoe/cs/autoquest/plugin/usability2/statistics/Histogramm.java @ 1326

Last change on this file since 1326 was 1326, checked in by khartmann, 10 years ago

Moved alexanders code into a new plugin project.
First commit of my experimental code (needs a lot of cleanup).

File size: 1.3 KB
Line 
1
2package de.ugoe.cs.autoquest.plugin.usability2.statistics;
3
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Map.Entry;
7
8import com.google.common.collect.Maps;
9import com.google.common.collect.Range;
10
11public class Histogramm {
12
13    final Map<Integer, Integer> data;
14
15    public Histogramm() {
16        this(new HashMap<Integer, Integer>());
17    }
18
19    private Histogramm(Map<Integer, Integer> data) {
20        this.data = new HashMap<Integer, Integer>(data);
21    }
22
23    public Histogramm removeLessThan(int border) {
24        Range<Integer> atLeast = Range.atLeast(border);
25        Map<Integer, Integer> filtered =
26            Maps.filterKeys(data, atLeast);
27        return new Histogramm(filtered);
28    }
29
30    public void add(int value) {
31        Integer count = data.get(value);
32        int cnt;
33        if (count == null) {
34            cnt = 1;
35        } else {
36            cnt = count + 1;
37        }
38       
39        System.out.print(".");
40       
41        data.put(value, cnt);
42    }
43   
44    public int count(int offset) {
45        int cnt = 0;
46        System.out.println(data.size());
47       
48        for (Entry<Integer, Integer> entry : data.entrySet()) {
49            cnt += (entry.getKey() + offset) * entry.getValue();
50        }
51        return cnt;
52    }
53   
54    public int count() {
55        return count(0);
56    }
57}
Note: See TracBrowser for help on using the repository browser.