1
|
/**
|
2
|
* Copyright (C) 2021 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.cdm.format.occurrences;
|
10
|
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
|
13
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
14
|
import eu.etaxonomy.cdm.common.UTF8;
|
15
|
|
16
|
/**
|
17
|
* @author a.mueller
|
18
|
* @since 31.03.2021
|
19
|
*/
|
20
|
public class DistanceStringFormatter {
|
21
|
|
22
|
/**
|
23
|
* Computes the correct distance string for given values for min, max and text.
|
24
|
* If text is not blank, text is returned, otherwise "min - max" or a single value is returned.
|
25
|
* @param min min value as number
|
26
|
* @param max max value as number
|
27
|
* @param text text representation of distance
|
28
|
* @return the formatted distance string
|
29
|
*/
|
30
|
public static String distanceString(Number min, Number max, String text, String unit) {
|
31
|
if (StringUtils.isNotBlank(text)){
|
32
|
return text;
|
33
|
}else{
|
34
|
String minStr = min == null? null : String.valueOf(min);
|
35
|
String maxStr = max == null? null : String.valueOf(max);
|
36
|
String result = CdmUtils.concat(UTF8.EN_DASH_SPATIUM.toString(), minStr, maxStr);
|
37
|
if (StringUtils.isNotBlank(result) && StringUtils.isNotBlank(unit)){
|
38
|
result = result + " " + unit;
|
39
|
}
|
40
|
return result;
|
41
|
}
|
42
|
}
|
43
|
}
|