Merge branch 'develop' into taxonDescription
[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.api.service.dto.TaxonRowWrapperDTO;
15 import eu.etaxonomy.cdm.model.common.MarkerType;
16 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
17 import eu.etaxonomy.cdm.model.description.Feature;
18 import eu.etaxonomy.cdm.model.description.QuantitativeData;
19 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
20 import eu.etaxonomy.cdm.model.taxon.Classification;
21 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22
23 /**
24 * Utility class for the character matrix editor
25 * @author pplitzner
26 * @since Jan 4, 2018
27 *
28 */
29 public class MatrixUtility {
30
31 /**
32 * Returns the column property string for the given {@link Feature}
33 * @param feature
34 * @return
35 */
36 public static String getProperty(Feature feature){
37 return feature.getLabel();
38 }
39
40 /**
41 * Returns a string representation for the given {@link QuantitativeData}
42 * @param data the quantitative data
43 * @return a string representation of the data
44 */
45 public static String getQuantitativeLabel(QuantitativeData data) {
46 String label = "";
47 Float min = data.getMin();
48 Float max = data.getMax();
49 if(min!=null||max!=null){
50 label += "["+(min!=null?min.toString():"?")+"-"+(max!=null?max.toString():"?")+"] ";
51 }
52 label += data.getStatisticalValues().stream().
53 filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
54 .map(exact->Float.toString(exact.getValue()))
55 .collect(Collectors.joining(", "));
56
57 return label;
58 }
59
60 /**
61 * Returns a string representation for the given min/max values
62 * @param minTotal the min value
63 * @param maxTotal the max value
64 * @return a string representation of the data
65 */
66 public static String getQuantitativeLabel(Float min, Float exact, Float max) {
67 return (min==null?"":"("+min.toString()+")") //$NON-NLS-1$
68 +(exact==null?"":exact.toString()) //$NON-NLS-1$
69 +(max==null?"":"("+max.toString()+")"); //$NON-NLS-1$
70 }
71
72 public static Classification getClassificationForDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
73 Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
74 if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
75 return taxonSubtreeFilter.iterator().next().getClassification();
76 }
77 return null;
78 }
79
80 public static boolean isDefaultTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
81 return hasMarker(taxonRowWrapperDTO, MarkerType.USE());
82 }
83
84 public static boolean isAggregatedTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
85 return hasMarker(taxonRowWrapperDTO, MarkerType.COMPUTED());
86 }
87
88 public static boolean isLiteratureTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
89 return hasMarker(taxonRowWrapperDTO, MarkerType.IN_BIBLIOGRAPHY());
90 }
91
92 private static boolean hasMarker(TaxonRowWrapperDTO taxonRowWrapperDTO, MarkerType markerType){
93 return taxonRowWrapperDTO.getDescription().getMarkers().stream()
94 .anyMatch(marker->marker.getMarkerType().equals(markerType));
95 }
96 }
97