1 package net.sourceforge.argval.collection;
2
3
4
5
6 public class CollectionUtilConfig {
7 public static final String DEFAULT_ARRAY_POSTFIX = "}";
8 public static final String DEFAULT_ARRAY_PREFIX = "{";
9 public static final String DEFAULT_ARRAY_VALUE_SEPARATOR = ",";
10 public static final String DEFAULT_ARRAY_VALUE_PREFIX = "'";
11 public static final String DEFAULT_ARRAY_VALUE_POSTFIX = DEFAULT_ARRAY_VALUE_PREFIX;
12 public static final String DEFAULT_ARRAY_KEY_PREFIX = "'";
13 public static final String DEFAULT_ARRAY_KEY_POSTFIX = DEFAULT_ARRAY_KEY_PREFIX;
14 public static final String DEFAULT_KEY_VALUE_SEPARATOR = ":";
15
16 private static final String EMPTY_STRING = "";
17
18 private String arrayPostfix = null;
19 private String arrayPrefix = null;
20 private String arrayValueSeparator = null;
21 private String arrayValuePostfix = null;
22 private String arrayValuePrefix = null;
23 private String arrayKeyPrefix = null;
24 private String arrayKeyPostfix = null;
25 private String keyValueSeparator = null;
26 private String extraSpace = " ";
27 private String nullValue = EMPTY_STRING;
28 private boolean isExtraSpacesActive = true;
29
30
31 public CollectionUtilConfig(String arrayPrefix, String arrayPostfix, String arrayValueSeparator, String arrayValuePrefix,
32 String arrayValuePostfix, String arrayKeyPrefix, String arrayKeyPostfix, String keyValueSeparator, String nullValue,
33 boolean isExtraSpacesActive) {
34 super();
35 this.isExtraSpacesActive = isExtraSpacesActive;
36 this.nullValue = polish(nullValue);
37 if (isExtraSpacesActive) {
38 this.arrayPostfix = addExtraSpace(arrayPostfix, extraSpace + arrayPostfix);
39 this.arrayPrefix = addExtraSpace(arrayPrefix, arrayPrefix + extraSpace);
40 this.arrayValueSeparator = addExtraSpace(arrayValueSeparator, arrayValueSeparator + extraSpace);
41 this.keyValueSeparator = addExtraSpace(keyValueSeparator, keyValueSeparator + extraSpace);
42 }
43 else {
44 this.arrayPostfix = polish(arrayPostfix);
45 this.arrayPrefix = polish(arrayPrefix);
46 this.arrayValueSeparator = polish(arrayValueSeparator);
47 this.keyValueSeparator = polish(keyValueSeparator);
48 }
49 this.arrayValuePostfix = polish(arrayValuePostfix);
50 this.arrayValuePrefix = polish(arrayValuePrefix);
51 this.arrayKeyPrefix = polish(arrayKeyPrefix);
52 this.arrayKeyPostfix = polish(arrayKeyPostfix);
53 }
54
55 private String addExtraSpace(String value, String valueWithExtraSpace) {
56 return (polish(value) == null) ? EMPTY_STRING : valueWithExtraSpace;
57 }
58
59 private String polish(String value) {
60 return (value == null) ? EMPTY_STRING : value;
61 }
62
63 public CollectionUtilConfig() {
64 this(DEFAULT_ARRAY_PREFIX, DEFAULT_ARRAY_POSTFIX, DEFAULT_ARRAY_VALUE_SEPARATOR, DEFAULT_ARRAY_VALUE_POSTFIX,
65 DEFAULT_ARRAY_VALUE_PREFIX, DEFAULT_ARRAY_KEY_PREFIX, DEFAULT_ARRAY_KEY_POSTFIX, DEFAULT_KEY_VALUE_SEPARATOR,
66 DEFAULT_ARRAY_VALUE_PREFIX + DEFAULT_ARRAY_VALUE_POSTFIX, true);
67 }
68
69
70 public String getArrayPostfix() {
71 return arrayPostfix;
72 }
73 public String getArrayPrefix() {
74 return arrayPrefix;
75 }
76 public String getArrayValuePostfix() {
77 return arrayValuePostfix;
78 }
79 public String getArrayValuePrefix() {
80 return arrayValuePrefix;
81 }
82 public String getArrayValueSeparator() {
83 return arrayValueSeparator;
84 }
85 public String getArrayKeyPrefix() {
86 return arrayKeyPrefix;
87 }
88 public String getArrayKeyPostfix() {
89 return arrayKeyPostfix;
90 }
91 public String getKeyValueSeparator() {
92 return keyValueSeparator;
93 }
94 public boolean isExtraSpacesActive() {
95 return isExtraSpacesActive;
96 }
97 public String getNullValue() {
98 return nullValue;
99 }
100
101 }