Merge branch 'hotfix/5.44.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / matrix / CategoricalDataHistogram.java
1 /**
2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.apache.commons.math3.stat.Frequency;
15
16 import eu.etaxonomy.cdm.model.description.Feature;
17 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
18
19 /**
20 * @author pplitzner
21 * @since Jul 12, 2018
22 */
23 public class CategoricalDataHistogram {
24
25 private Feature feature;
26 private Frequency frequency;
27 private List<DefinedTermBase<?>> states;
28
29 public CategoricalDataHistogram(Feature feature) {
30 this.feature = feature;
31 this.states = new ArrayList<>();
32 this.frequency = new Frequency();
33 feature.getSupportedCategoricalEnumerations()
34 .forEach(terms->terms.getDistinctTerms()
35 .forEach(state->states.add(state)));
36 }
37
38 public void addState(DefinedTermBase<?> state){
39 frequency.addValue(state.getLabel());
40 }
41
42 public long getCount(DefinedTermBase<?> state){
43 return frequency.getCount(state.getLabel());
44 }
45
46 public List<DefinedTermBase<?>> getStates() {
47 return states;
48 }
49
50 public Feature getFeature() {
51 return feature;
52 }
53 }