Project

General

Profile

« Previous | Next » 

Revision a3a12095

Added by Patrick Plitzner almost 6 years ago

ref #7549 Add/use apache common math for frequency distribution

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CategoricalDataHistogram.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10 10

  
11
import java.util.HashMap;
12
import java.util.Map;
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.apache.commons.math3.stat.Frequency;
13 15

  
14 16
import eu.etaxonomy.cdm.model.description.Feature;
15 17
import eu.etaxonomy.cdm.model.description.State;
......
22 24
public class CategoricalDataHistogram {
23 25

  
24 26
    private Feature feature;
25
    private Map<State, Integer> stateCountMap;
27
    private Frequency frequency;
28
    private List<State> states;
26 29

  
27 30
    public CategoricalDataHistogram(Feature feature) {
28 31
        this.feature = feature;
29
        this.stateCountMap = new HashMap<>();
32
        this.states = new ArrayList<>();
33
        this.frequency = new Frequency();
30 34
        feature.getSupportedCategoricalEnumerations()
31 35
        .forEach(voc->voc.getTerms()
32
                .forEach(state->stateCountMap.put(state, 0)));
36
                .forEach(state->states.add(state)));
33 37
    }
34 38

  
35 39
    public void addState(State state){
36
        Integer integer = stateCountMap.get(state);
37
        stateCountMap.put(state, integer+1);
40
        frequency.addValue(state.getLabel());
41
    }
42

  
43
    public long getCount(State state){
44
        return frequency.getCount(state.getLabel());
38 45
    }
39 46

  
40
    public Map<State, Integer> getStateCountMap() {
41
        return stateCountMap;
47
    public List<State> getStates() {
48
        return states;
42 49
    }
43 50

  
44 51
    public Feature getFeature() {

Also available in: Unified diff