Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/JSONHelper.java @ 16473:f681a647246c
uppercase JSON for consistency
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Thu, 10 Jul 2014 20:43:26 +0200 |
parents | 0e092c1ecd64 |
children | c88ab4f1f04a |
comparison
equal
deleted
inserted
replaced
16472:83dce5b6cb41 | 16473:f681a647246c |
---|---|
120 | 120 |
121 public static void restart() { | 121 public static void restart() { |
122 AstJsonDumpBuilder = new StringBuilder(); | 122 AstJsonDumpBuilder = new StringBuilder(); |
123 } | 123 } |
124 | 124 |
125 public static JsonObjectBuilder object() { | 125 public static JSONObjectBuilder object() { |
126 return new JsonObjectBuilder(); | 126 return new JSONObjectBuilder(); |
127 } | 127 } |
128 | 128 |
129 public static JsonArrayBuilder array() { | 129 public static JSONArrayBuilder array() { |
130 return new JsonArrayBuilder(); | 130 return new JSONArrayBuilder(); |
131 } | 131 } |
132 | 132 |
133 public static abstract class JsonStringBuilder { | 133 public static abstract class JSONStringBuilder { |
134 @Override | 134 @Override |
135 public final String toString() { | 135 public final String toString() { |
136 StringBuilder sb = new StringBuilder(); | 136 StringBuilder sb = new StringBuilder(); |
137 appendTo(sb); | 137 appendTo(sb); |
138 return sb.toString(); | 138 return sb.toString(); |
139 } | 139 } |
140 | 140 |
141 protected abstract void appendTo(StringBuilder sb); | 141 protected abstract void appendTo(StringBuilder sb); |
142 | 142 |
143 protected static void appendValue(StringBuilder sb, Object value) { | 143 protected static void appendValue(StringBuilder sb, Object value) { |
144 if (value instanceof JsonStringBuilder) { | 144 if (value instanceof JSONStringBuilder) { |
145 ((JsonStringBuilder) value).appendTo(sb); | 145 ((JSONStringBuilder) value).appendTo(sb); |
146 } else if (value instanceof Integer || value instanceof Boolean || value == null) { | 146 } else if (value instanceof Integer || value instanceof Boolean || value == null) { |
147 sb.append(value); | 147 sb.append(value); |
148 } else { | 148 } else { |
149 sb.append(quote(String.valueOf(value))); | 149 sb.append(quote(String.valueOf(value))); |
150 } | 150 } |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 public static final class JsonObjectBuilder extends JsonStringBuilder { | 154 public static final class JSONObjectBuilder extends JSONStringBuilder { |
155 private final Map<String, Object> contents = new LinkedHashMap<>(); | 155 private final Map<String, Object> contents = new LinkedHashMap<>(); |
156 | 156 |
157 private JsonObjectBuilder() { | 157 private JSONObjectBuilder() { |
158 } | 158 } |
159 | 159 |
160 public JsonObjectBuilder add(String key, String value) { | 160 public JSONObjectBuilder add(String key, String value) { |
161 contents.put(key, value); | 161 contents.put(key, value); |
162 return this; | 162 return this; |
163 } | 163 } |
164 | 164 |
165 public JsonObjectBuilder add(String key, Number value) { | 165 public JSONObjectBuilder add(String key, Number value) { |
166 contents.put(key, value); | 166 contents.put(key, value); |
167 return this; | 167 return this; |
168 } | 168 } |
169 | 169 |
170 public JsonObjectBuilder add(String key, Boolean value) { | 170 public JSONObjectBuilder add(String key, Boolean value) { |
171 contents.put(key, value); | 171 contents.put(key, value); |
172 return this; | 172 return this; |
173 } | 173 } |
174 | 174 |
175 public JsonObjectBuilder add(String key, JsonStringBuilder value) { | 175 public JSONObjectBuilder add(String key, JSONStringBuilder value) { |
176 contents.put(key, value); | 176 contents.put(key, value); |
177 return this; | 177 return this; |
178 } | 178 } |
179 | 179 |
180 @Override | 180 @Override |
192 } | 192 } |
193 sb.append("}"); | 193 sb.append("}"); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 public static final class JsonArrayBuilder extends JsonStringBuilder { | 197 public static final class JSONArrayBuilder extends JSONStringBuilder { |
198 private final List<Object> contents = new ArrayList<>(); | 198 private final List<Object> contents = new ArrayList<>(); |
199 | 199 |
200 private JsonArrayBuilder() { | 200 private JSONArrayBuilder() { |
201 } | 201 } |
202 | 202 |
203 public JsonArrayBuilder add(String value) { | 203 public JSONArrayBuilder add(String value) { |
204 contents.add(value); | 204 contents.add(value); |
205 return this; | 205 return this; |
206 } | 206 } |
207 | 207 |
208 public JsonArrayBuilder add(Number value) { | 208 public JSONArrayBuilder add(Number value) { |
209 contents.add(value); | 209 contents.add(value); |
210 return this; | 210 return this; |
211 } | 211 } |
212 | 212 |
213 public JsonArrayBuilder add(Boolean value) { | 213 public JSONArrayBuilder add(Boolean value) { |
214 contents.add(value); | 214 contents.add(value); |
215 return this; | 215 return this; |
216 } | 216 } |
217 | 217 |
218 public JsonArrayBuilder add(JsonStringBuilder value) { | 218 public JSONArrayBuilder add(JSONStringBuilder value) { |
219 contents.add(value); | 219 contents.add(value); |
220 return this; | 220 return this; |
221 } | 221 } |
222 | 222 |
223 @Override | 223 @Override |