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
|
package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
public final class KeyValueParameter implements StructuredParameter {
private final String key;
private final JsonValue value;
private KeyValueParameter(String key, JsonValue value) {
this.key = key;
this.value = value;
}
public static KeyValueParameter of(String key, String value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, int value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, long value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, double value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, BigDecimal value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, BigInteger value) {
return new KeyValueParameter(key, Json.createValue(value));
}
public static KeyValueParameter of(String key, boolean value) {
return new KeyValueParameter(key, value ? JsonValue.TRUE : JsonValue.FALSE);
}
@Override
public JsonObjectBuilder json() {
return Json.createObjectBuilder().add(key, value);
}
public String key() {
return key;
}
public JsonValue value() {
return value;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (KeyValueParameter) obj;
return Objects.equals(this.key, that.key) && Objects.equals(this.value, that.value);
}
@Override
public int hashCode() {
return Objects.hash(key, value);
}
@Override
public String toString() {
return "KeyValueParameter[" + "key=" + key + ", " + "value=" + value + ']';
}
}
|