Project

General

Profile

Download (1.58 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.occurrences;
10

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

    
14
import eu.etaxonomy.cdm.common.CdmUtils;
15
import eu.etaxonomy.cdm.format.ICdmFormatter;
16

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

    
24
    protected FormatKey[] formatKeys;
25
    
26
    protected Map<FormatKey, String> formatKeyMap = new HashMap<ICdmFormatter.FormatKey, String>();
27

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

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

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

    
57
}
(1-1/9)