5151 * JsonArray array = Json.array(names);
5252 * </pre>
5353 */
54- public final class Json
55- {
54+ public final class Json {
5655
57- private Json ()
58- {
56+ private Json () {
5957 // not meant to be instantiated
6058 }
6159
@@ -80,8 +78,7 @@ private Json()
8078 * @param value the value to get a JSON representation for
8179 * @return a JSON value that represents the given value
8280 */
83- public static JsonValue value (int value )
84- {
81+ public static JsonValue value (int value ) {
8582 return new JsonNumber (Integer .toString (value , 10 ));
8683 }
8784
@@ -91,8 +88,7 @@ public static JsonValue value(int value)
9188 * @param value the value to get a JSON representation for
9289 * @return a JSON value that represents the given value
9390 */
94- public static JsonValue value (long value )
95- {
91+ public static JsonValue value (long value ) {
9692 return new JsonNumber (Long .toString (value , 10 ));
9793 }
9894
@@ -102,10 +98,8 @@ public static JsonValue value(long value)
10298 * @param value the value to get a JSON representation for
10399 * @return a JSON value that represents the given value
104100 */
105- public static JsonValue value (float value )
106- {
107- if (Float .isInfinite (value ) || Float .isNaN (value ))
108- {
101+ public static JsonValue value (float value ) {
102+ if (Float .isInfinite (value ) || Float .isNaN (value )) {
109103 throw new IllegalArgumentException ("Infinite and NaN values not permitted in JSON" );
110104 }
111105 return new JsonNumber (cutOffPointZero (Float .toString (value )));
@@ -117,10 +111,8 @@ public static JsonValue value(float value)
117111 * @param value the value to get a JSON representation for
118112 * @return a JSON value that represents the given value
119113 */
120- public static JsonValue value (double value )
121- {
122- if (Double .isInfinite (value ) || Double .isNaN (value ))
123- {
114+ public static JsonValue value (double value ) {
115+ if (Double .isInfinite (value ) || Double .isNaN (value )) {
124116 throw new IllegalArgumentException ("Infinite and NaN values not permitted in JSON" );
125117 }
126118 return new JsonNumber (cutOffPointZero (Double .toString (value )));
@@ -132,8 +124,7 @@ public static JsonValue value(double value)
132124 * @param string the string to get a JSON representation for
133125 * @return a JSON value that represents the given string
134126 */
135- public static JsonValue value (String string )
136- {
127+ public static JsonValue value (String string ) {
137128 return string == null ? NULL : new JsonString (string );
138129 }
139130
@@ -143,8 +134,7 @@ public static JsonValue value(String string)
143134 * @param value the value to get a JSON representation for
144135 * @return a JSON value that represents the given value
145136 */
146- public static JsonValue value (boolean value )
147- {
137+ public static JsonValue value (boolean value ) {
148138 return value ? TRUE : FALSE ;
149139 }
150140
@@ -154,8 +144,7 @@ public static JsonValue value(boolean value)
154144 *
155145 * @return a new empty JSON array
156146 */
157- public static JsonValue array ()
158- {
147+ public static JsonValue array () {
159148 return new JsonArray ();
160149 }
161150
@@ -166,15 +155,12 @@ public static JsonValue array()
166155 * @param values the values to be included in the new JSON array
167156 * @return a new JSON array that contains the given values
168157 */
169- public static JsonArray array (int ... values )
170- {
171- if (values == null )
172- {
158+ public static JsonArray array (int ... values ) {
159+ if (values == null ) {
173160 throw new NullPointerException ("values is null" );
174161 }
175162 JsonArray array = new JsonArray ();
176- for (int value : values )
177- {
163+ for (int value : values ) {
178164 array .add (value );
179165 }
180166 return array ;
@@ -187,15 +173,12 @@ public static JsonArray array(int... values)
187173 * @param values the values to be included in the new JSON array
188174 * @return a new JSON array that contains the given values
189175 */
190- public static JsonArray array (long ... values )
191- {
192- if (values == null )
193- {
176+ public static JsonArray array (long ... values ) {
177+ if (values == null ) {
194178 throw new NullPointerException ("values is null" );
195179 }
196180 JsonArray array = new JsonArray ();
197- for (long value : values )
198- {
181+ for (long value : values ) {
199182 array .add (value );
200183 }
201184 return array ;
@@ -208,15 +191,12 @@ public static JsonArray array(long... values)
208191 * @param values the values to be included in the new JSON array
209192 * @return a new JSON array that contains the given values
210193 */
211- public static JsonArray array (float ... values )
212- {
213- if (values == null )
214- {
194+ public static JsonArray array (float ... values ) {
195+ if (values == null ) {
215196 throw new NullPointerException ("values is null" );
216197 }
217198 JsonArray array = new JsonArray ();
218- for (float value : values )
219- {
199+ for (float value : values ) {
220200 array .add (value );
221201 }
222202 return array ;
@@ -229,15 +209,12 @@ public static JsonArray array(float... values)
229209 * @param values the values to be included in the new JSON array
230210 * @return a new JSON array that contains the given values
231211 */
232- public static JsonArray array (double ... values )
233- {
234- if (values == null )
235- {
212+ public static JsonArray array (double ... values ) {
213+ if (values == null ) {
236214 throw new NullPointerException ("values is null" );
237215 }
238216 JsonArray array = new JsonArray ();
239- for (double value : values )
240- {
217+ for (double value : values ) {
241218 array .add (value );
242219 }
243220 return array ;
@@ -250,15 +227,12 @@ public static JsonArray array(double... values)
250227 * @param values the values to be included in the new JSON array
251228 * @return a new JSON array that contains the given values
252229 */
253- public static JsonArray array (boolean ... values )
254- {
255- if (values == null )
256- {
230+ public static JsonArray array (boolean ... values ) {
231+ if (values == null ) {
257232 throw new NullPointerException ("values is null" );
258233 }
259234 JsonArray array = new JsonArray ();
260- for (boolean value : values )
261- {
235+ for (boolean value : values ) {
262236 array .add (value );
263237 }
264238 return array ;
@@ -270,15 +244,12 @@ public static JsonArray array(boolean... values)
270244 * @param strings the strings to be included in the new JSON array
271245 * @return a new JSON array that contains the given strings
272246 */
273- public static JsonArray array (String ... strings )
274- {
275- if (strings == null )
276- {
247+ public static JsonArray array (String ... strings ) {
248+ if (strings == null ) {
277249 throw new NullPointerException ("values is null" );
278250 }
279251 JsonArray array = new JsonArray ();
280- for (String value : strings )
281- {
252+ for (String value : strings ) {
282253 array .add (value );
283254 }
284255 return array ;
@@ -290,8 +261,7 @@ public static JsonArray array(String... strings)
290261 *
291262 * @return a new empty JSON object
292263 */
293- public static JsonObject object ()
294- {
264+ public static JsonObject object () {
295265 return new JsonObject ();
296266 }
297267
@@ -303,18 +273,13 @@ public static JsonObject object()
303273 * @return a value that represents the parsed JSON
304274 * @throws ParseException if the input is not valid JSON
305275 */
306- public static JsonValue parse (String string )
307- {
308- if (string == null )
309- {
276+ public static JsonValue parse (String string ) {
277+ if (string == null ) {
310278 throw new NullPointerException ("string is null" );
311279 }
312- try
313- {
280+ try {
314281 return new JsonParser (string ).parse ();
315- }
316- catch (IOException exception )
317- {
282+ } catch (IOException exception ) {
318283 // JsonParser does not throw IOException for String
319284 throw new RuntimeException (exception );
320285 }
@@ -334,19 +299,15 @@ public static JsonValue parse(String string)
334299 * @throws IOException if an I/O error occurs in the reader
335300 * @throws ParseException if the input is not valid JSON
336301 */
337- public static JsonValue parse (Reader reader ) throws IOException
338- {
339- if (reader == null )
340- {
302+ public static JsonValue parse (Reader reader ) throws IOException {
303+ if (reader == null ) {
341304 throw new NullPointerException ("reader is null" );
342305 }
343306 return new JsonParser (reader ).parse ();
344307 }
345308
346- private static String cutOffPointZero (String string )
347- {
348- if (string .endsWith (".0" ))
349- {
309+ private static String cutOffPointZero (String string ) {
310+ if (string .endsWith (".0" )) {
350311 return string .substring (0 , string .length () - 2 );
351312 }
352313 return string ;
0 commit comments