1 package org.esigate.test;
2
3 import java.util.Properties;
4
5
6
7
8
9
10
11
12
13
14 public class PropertiesBuilder {
15
16 private Properties prop = new Properties();
17 private Properties target = null;
18
19
20
21
22 public PropertiesBuilder() {
23 }
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 @SuppressWarnings("rawtypes")
43 public PropertiesBuilder set(Object key, Object... value) {
44
45 String objectValue = "";
46 boolean first = true;
47
48 for (int i = 0; i < value.length; i++) {
49
50
51 if (first)
52 first = false;
53 else
54 objectValue = objectValue + ",";
55
56
57 Object o = value[i];
58
59 if (o instanceof Class) {
60 objectValue = objectValue + ((Class) o).getName();
61 }
62
63 else {
64
65 objectValue = o.toString();
66 }
67 }
68
69 return this.set(key.toString(), objectValue);
70 }
71
72
73
74
75
76
77
78
79
80
81
82 public PropertiesBuilder set(String key, String value) {
83 prop.setProperty(key, value);
84 return this;
85 }
86
87
88
89
90
91
92
93
94 public PropertiesBuilder on(Properties p) {
95 target = p;
96 return this;
97 }
98
99
100
101
102
103
104 public Properties build() {
105
106 if (target != null) {
107
108 target.putAll(prop);
109 } else {
110 target = prop;
111 }
112
113 return target;
114 }
115 }