2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
;
12 import java
.util
.stream
.Collectors
;
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
;
24 * Utility class for the character matrix editor
29 public class MatrixUtility
{
32 * Returns the column property string for the given {@link Feature}
36 public static String
getProperty(Feature feature
){
37 return feature
.getLabel();
41 * Returns a string representation for the given {@link QuantitativeData}
42 * @param data the quantitative data
43 * @return a string representation of the data
45 public static String
getQuantitativeLabel(QuantitativeData data
) {
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():"?")+"] ";
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(", "));
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
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$
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();
80 public static boolean isDefaultTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
81 return hasMarker(taxonRowWrapperDTO
, MarkerType
.USE());
84 public static boolean isAggregatedTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
85 return hasMarker(taxonRowWrapperDTO
, MarkerType
.COMPUTED());
88 public static boolean isLiteratureTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
89 return hasMarker(taxonRowWrapperDTO
, MarkerType
.IN_BIBLIOGRAPHY());
92 private static boolean hasMarker(TaxonRowWrapperDTO taxonRowWrapperDTO
, MarkerType markerType
){
93 return taxonRowWrapperDTO
.getDescription().getMarkers().stream()
94 .anyMatch(marker
->marker
.getMarkerType().equals(markerType
));