-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathKeyValue.java
More file actions
95 lines (78 loc) · 2.56 KB
/
KeyValue.java
File metadata and controls
95 lines (78 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.motechproject.eventlogging.matchers;
import java.util.Map;
/**
* Class representing mapping from one parameter key-value pair to another.
* Used in {@link org.motechproject.eventlogging.converter.impl.DefaultDbToLogConverter}
* to replace those pairs before persisting logs in the database.
*/
public class KeyValue {
private String startKey;
private Object startValue;
private String endKey;
private Object endValue;
private boolean isOptional;
/**
* Creates an instance of KeyValue from passed parameters. If an event contains key specified
* in startKey and value of this key equals startValue, then that key will be replaced by endKey
* and that value by endValue.
*
* @param startKey key to replace
* @param startValue value of replacing key
* @param endKey new key
* @param endValue new value for new key
* @param isOptional have no use at the moment
*/
public KeyValue(String startKey, Object startValue, String endKey, Object endValue, boolean isOptional) {
this.startKey = startKey;
this.startValue = startValue;
this.endKey = endKey;
this.endValue = endValue;
this.isOptional = isOptional;
}
public boolean isOptional() {
return isOptional;
}
public void setOptional(boolean isOptional) {
this.isOptional = isOptional;
}
public String getStartKey() {
return startKey;
}
public void setStartKey(String startKey) {
this.startKey = startKey;
}
public Object getStartValue() {
return startValue;
}
public void setStartValue(Object startValue) {
this.startValue = startValue;
}
public String getEndKey() {
return endKey;
}
public void setEndKey(String endKey) {
this.endKey = endKey;
}
public Object getEndValue() {
return endValue;
}
public void setEndValue(Object endValue) {
this.endValue = endValue;
}
public static KeyValue buildFromMap(Map<String, String> map) {
String startKey = null;
String startValue = null;
String endKey = null;
String endValue = null;
for (Map.Entry<String, String> entry : map.entrySet()) {
if (startKey == null) {
startKey = entry.getKey();
startValue = entry.getValue();
} else {
endKey = entry.getKey();
endValue = entry.getValue();
}
}
return new KeyValue(startKey, startValue, endKey, endValue, true);
}
}