3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.format
.occurrences
;
12 import java
.util
.HashMap
;
15 import eu
.etaxonomy
.cdm
.format
.ICdmFormatter
;
22 public abstract class AbstractCdmFormatter
implements ICdmFormatter
{
24 protected FormatKey
[] formatKeys
;
26 protected Map
<FormatKey
, String
> formatKeyMap
= new HashMap
<ICdmFormatter
.FormatKey
, String
>();
28 public AbstractCdmFormatter(Object object
, FormatKey
[] formatKeys
) {
29 this.formatKeys
= formatKeys
;
30 initFormatKeys(object
);
34 public String
format(Object object
, FormatKey
... formatKeys
) {
35 StringBuilder builder
= new StringBuilder();
36 for (FormatKey formatKey
: formatKeys
) {
37 String string
= formatKeyMap
.get(formatKey
);
39 builder
.append(string
);
42 return builder
.toString().trim();
46 public String
format(Object object
) {
47 StringBuilder builder
= new StringBuilder();
48 for (FormatKey formatKey
: formatKeys
) {
49 String string
= formatKeyMap
.get(formatKey
);
51 builder
.append(string
);
54 return builder
.toString().trim();
57 protected void initFormatKeys(Object object
){
58 formatKeyMap
.put(FormatKey
.CLOSE_BRACKET
, ")");
59 formatKeyMap
.put(FormatKey
.OPEN_BRACKET
, "(");
60 formatKeyMap
.put(FormatKey
.SPACE
, " ");
61 formatKeyMap
.put(FormatKey
.COMMA
, ",");