Project

General

Profile

Download (1.92 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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;
10

    
11
import java.util.HashMap;
12
import java.util.Map;
13

    
14
import org.apache.commons.lang3.StringUtils;
15

    
16
/**
17
 * @author pplitzner
18
 * @since Nov 30, 2015
19
 */
20
public abstract class AbstractCdmFormatter implements ICdmFormatter {
21

    
22

    
23
    public static final String COMMA_CHAR = ",";
24
    public static final String SPACE_CHAR = " ";
25
    public static final String OPEN_BRACKET_CHAR = "(";
26
    public static final String CLOSE_BRACKET_CHAR = ")";
27

    
28
    protected FormatKey[] formatKeys;
29

    
30
    protected Map<FormatKey, String> formatKeyMap = new HashMap<>();
31

    
32
    public AbstractCdmFormatter(Object object, FormatKey[] formatKeys) {
33
    	this.formatKeys = formatKeys;
34
        initFormatKeys(object);
35
    }
36

    
37
    @Override
38
    public String format(Object object, FormatKey... formatKeys) {
39
        StringBuilder builder = new StringBuilder();
40
        for (FormatKey formatKey : formatKeys) {
41
            String string = formatKeyMap.get(formatKey);
42
            if(string!=null){
43
                builder.append(string);
44
            }
45
        }
46
        return builder.toString().trim();
47
    }
48

    
49
    @Override
50
    public String format(Object object) {
51
    	return format(object, formatKeys);
52
    }
53

    
54
    protected void initFormatKeys(Object object){
55
        formatKeyMap.put(FormatKey.CLOSE_BRACKET, CLOSE_BRACKET_CHAR);
56
        formatKeyMap.put(FormatKey.OPEN_BRACKET, OPEN_BRACKET_CHAR);
57
        formatKeyMap.put(FormatKey.SPACE, SPACE_CHAR);
58
        formatKeyMap.put(FormatKey.COMMA, COMMA_CHAR);
59
    }
60

    
61

    
62
    protected boolean isNotBlank(String str) {
63
        return StringUtils.isNotBlank(str);
64
    }
65

    
66
    protected boolean isBlank(String str) {
67
        return StringUtils.isBlank(str);
68
    }
69

    
70
}
(1-1/10)