ref #7575 Merge aggregated and exact value cell editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / matrix / MatrixUtility.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.Set;
12 import java.util.stream.Collectors;
13
14 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
15 import eu.etaxonomy.cdm.model.description.Feature;
16 import eu.etaxonomy.cdm.model.description.QuantitativeData;
17 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
18 import eu.etaxonomy.cdm.model.taxon.Classification;
19 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20
21 /**
22 * Utility class for the character matrix editor
23 * @author pplitzner
24 * @since Jan 4, 2018
25 *
26 */
27 public class MatrixUtility {
28
29 /**
30 * Returns the column property string for the given {@link Feature}
31 * @param feature
32 * @return
33 */
34 public static String getProperty(Feature feature){
35 return feature.getLabel();
36 }
37
38 /**
39 * Returns a string representation for the given {@link QuantitativeData}
40 * @param data the quantitative data
41 * @return a string representation of the data
42 */
43 public static String getQuantitativeLabel(QuantitativeData data) {
44 return data.getStatisticalValues().stream().
45 filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
46 .map(exact->Float.toString(exact.getValue()))
47 .collect(Collectors.joining(", "));
48 }
49
50 /**
51 * Returns a string representation for the given min/max values
52 * @param minTotal the min value
53 * @param maxTotal the max value
54 * @return a string representation of the data
55 */
56 public static String getQuantitativeLabel(Float min, Float exact, Float max) {
57 return (min==null?"":"("+min.toString()+")") //$NON-NLS-1$
58 +(exact==null?"":exact.toString()) //$NON-NLS-1$
59 +(max==null?"":"("+max.toString()+")"); //$NON-NLS-1$
60 }
61
62
63 public static Classification getClassificationForDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
64 Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
65 if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
66 return taxonSubtreeFilter.iterator().next().getClassification();
67 }
68 return null;
69 }
70 }
71