Project

General

Profile

Download (1.67 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
    protected FormatKey[] formatKeys;
23

    
24
    protected Map<FormatKey, String> formatKeyMap = new HashMap<>();
25

    
26
    public AbstractCdmFormatter(Object object, FormatKey[] formatKeys) {
27
    	this.formatKeys = formatKeys;
28
        initFormatKeys(object);
29
    }
30

    
31
    @Override
32
    public String format(Object object, FormatKey... formatKeys) {
33
        StringBuilder builder = new StringBuilder();
34
        for (FormatKey formatKey : formatKeys) {
35
            String string = formatKeyMap.get(formatKey);
36
            if(string!=null){
37
                builder.append(string);
38
            }
39
        }
40
        return builder.toString().trim();
41
    }
42

    
43
    @Override
44
    public String format(Object object) {
45
    	return format(object, formatKeys);
46
    }
47

    
48
    protected void initFormatKeys(Object object){
49
        formatKeyMap.put(FormatKey.CLOSE_BRACKET, ")");
50
        formatKeyMap.put(FormatKey.OPEN_BRACKET, "(");
51
        formatKeyMap.put(FormatKey.SPACE, " ");
52
        formatKeyMap.put(FormatKey.COMMA, ",");
53
    }
54

    
55

    
56
    protected boolean isNotBlank(String str) {
57
        return StringUtils.isNotBlank(str);
58
    }
59

    
60
    protected boolean isBlank(String str) {
61
        return StringUtils.isBlank(str);
62
    }
63

    
64
}
(1-1/7)