forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonKeyValuePair.java
More file actions
164 lines (136 loc) · 4.31 KB
/
JsonKeyValuePair.java
File metadata and controls
164 lines (136 loc) · 4.31 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import java.io.Serializable;
import java.util.Objects;
/**
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public class JsonKeyValuePair implements Serializable {
private final Object key;
private final Object value;
private boolean usingKeyKeyword;
private JsonKeyValuePairSeparator separator;
private boolean usingFormatJson = false;
/**
* Please use the Constructor with {@link JsonKeyValuePairSeparator} parameter.
*/
@Deprecated
public JsonKeyValuePair(Object key, Object value, boolean usingKeyKeyword,
boolean usingValueKeyword) {
this(key, value, usingKeyKeyword, usingValueKeyword ? JsonKeyValuePairSeparator.VALUE
: JsonKeyValuePairSeparator.COLON);
}
public JsonKeyValuePair(Object key, Object value, boolean usingKeyKeyword,
JsonKeyValuePairSeparator separator) {
this.key = Objects.requireNonNull(key, "The KEY of the Pair must not be null");
this.value = value;
this.usingKeyKeyword = usingKeyKeyword;
this.separator =
Objects.requireNonNull(separator, "The KeyValuePairSeparator must not be NULL");
}
public boolean isUsingKeyKeyword() {
return usingKeyKeyword;
}
public void setUsingKeyKeyword(boolean usingKeyKeyword) {
this.usingKeyKeyword = usingKeyKeyword;
}
public JsonKeyValuePair withUsingKeyKeyword(boolean usingKeyKeyword) {
this.setUsingKeyKeyword(usingKeyKeyword);
return this;
}
/**
* Use {@link #getSeparator()}
*/
@Deprecated
public boolean isUsingValueKeyword() {
return separator == JsonKeyValuePairSeparator.VALUE;
}
/**
* Use {@link #setSeparator(JsonKeyValuePairSeparator)}
*/
@Deprecated
public void setUsingValueKeyword(boolean usingValueKeyword) {
separator = usingValueKeyword ? JsonKeyValuePairSeparator.VALUE
: JsonKeyValuePairSeparator.COLON;
}
/**
* Use {@link #withSeparator(JsonKeyValuePairSeparator)}
*/
@Deprecated
public JsonKeyValuePair withUsingValueKeyword(boolean usingValueKeyword) {
this.setUsingValueKeyword(usingValueKeyword);
return this;
}
public JsonKeyValuePairSeparator getSeparator() {
return separator;
}
public void setSeparator(JsonKeyValuePairSeparator separator) {
this.separator = separator;
}
public JsonKeyValuePair withSeparator(JsonKeyValuePairSeparator separator) {
this.setSeparator(separator);
return this;
}
public boolean isUsingFormatJson() {
return usingFormatJson;
}
public void setUsingFormatJson(boolean usingFormatJson) {
this.usingFormatJson = usingFormatJson;
}
public JsonKeyValuePair withUsingFormatJson(boolean usingFormatJson) {
this.setUsingFormatJson(usingFormatJson);
return this;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.key);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final JsonKeyValuePair other = (JsonKeyValuePair) obj;
return Objects.equals(this.key, other.key);
}
public Object getKey() {
return key;
}
public Object getValue() {
return value;
}
public StringBuilder append(StringBuilder builder) {
if (isUsingKeyKeyword() && getSeparator() == JsonKeyValuePairSeparator.VALUE) {
builder.append("KEY ");
}
builder.append(getKey());
if (getValue() != null) {
builder.append(getSeparator().getSeparatorString());
builder.append(getValue());
}
if (isUsingFormatJson()) {
builder.append(" FORMAT JSON");
}
return builder;
}
@Override
public String toString() {
return append(new StringBuilder()).toString();
}
}