Skip to content

Commit 9dcd124

Browse files
committed
[java] Formatting files
1 parent 6bff9b0 commit 9dcd124

File tree

6 files changed

+276
-296
lines changed

6 files changed

+276
-296
lines changed

java/src/org/openqa/selenium/json/Input.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,28 @@
2424

2525
/**
2626
* Similar to a {@link Reader} but with the ability to peek a single character ahead.
27-
* <p>
28-
* For the sake of providing a useful {@link #toString()} implementation, keeps the most recently
27+
*
28+
* <p>For the sake of providing a useful {@link #toString()} implementation, keeps the most recently
2929
* read characters in the input buffer.
3030
*/
3131
class Input {
3232
/** end-of-file indicator (0xFFFD) */
3333
public static final char EOF = (char) -1; // NOTE: Produces Unicode replacement character (0xFFFD)
34+
3435
/** the number of chars to buffer */
3536
private static final int BUFFER_SIZE = 4096;
37+
3638
/** the number of chars to remember, safe to set to 0 */
3739
private static final int MEMORY_SIZE = 128;
3840

3941
private final Reader source;
42+
4043
/** a buffer used to minimize read calls and to keep the chars to remember */
4144
private final char[] buffer;
45+
4246
/** the filled area in the buffer */
4347
private int filled;
48+
4449
/** the last position read in the buffer */
4550
private int position;
4651

java/src/org/openqa/selenium/json/Json.java

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -30,79 +30,87 @@
3030
/**
3131
* The <b>Json</b> class is the entrypoint for the JSON processing features of the Selenium API.
3232
* These features include:
33+
*
3334
* <ul>
34-
* <li>Built-in JSON deserialization to primitives and collections from the standard types shown below.</li>
35+
* <li>Built-in JSON deserialization to primitives and collections from the standard types shown
36+
* below.
3537
* <li>Facilities to deserialize JSON to custom data types:
36-
* <ul>
37-
* <li>Classes that declare a {@code fromJson(T)} static method, where <b>T</b> is any of the standard
38-
* types shown below.</li>
39-
* <li>Classes that declare a {@code fromJson(JsonInput)} static method.<br>
40-
* <b>NOTE</b>: Objects deserialized via a {@code fromJson} static method can be immutable.</li>
41-
* <li>Classes that declare setter methods adhering to the
42-
* <a href="https://docs.oracle.com/javase/tutorial/javabeans/writing/index.html">JavaBean</a>
43-
* specification.<br>
44-
* <b>NOTE</b>: Deserialized {@code JavaBean} objects are mutable, which may be undesirable.</li>
45-
* </ul>
46-
* </li>
47-
* <li>Built-in JSON serialization from primitives and collections from the standard types shown below.</li>
38+
* <ul>
39+
* <li>Classes that declare a {@code fromJson(T)} static method, where <b>T</b> is any of
40+
* the standard types shown below.
41+
* <li>Classes that declare a {@code fromJson(JsonInput)} static method.<br>
42+
* <b>NOTE</b>: Objects deserialized via a {@code fromJson} static method can be
43+
* immutable.
44+
* <li>Classes that declare setter methods adhering to the <a
45+
* href="https://docs.oracle.com/javase/tutorial/javabeans/writing/index.html">JavaBean</a>
46+
* specification.<br>
47+
* <b>NOTE</b>: Deserialized {@code JavaBean} objects are mutable, which may be
48+
* undesirable.
49+
* </ul>
50+
* <li>Built-in JSON serialization from primitives and collections from the standard types shown
51+
* below.
4852
* <li>Facilities to serialize custom data types to JSON:
49-
* <ul>
50-
* <li>Classes that declare a {@code toJson()} method returning a primitive or collection from
51-
* the standard types shown below.</li>
52-
* <li>Classes that declare getter methods adhering to the {@code JavaBean} specification.</li>
53-
* </ul>
54-
* </li>
53+
* <ul>
54+
* <li>Classes that declare a {@code toJson()} method returning a primitive or collection
55+
* from the standard types shown below.
56+
* <li>Classes that declare getter methods adhering to the {@code JavaBean} specification.
57+
* </ul>
5558
* </ul>
5659
*
5760
* The standard types supported by built-in processing:
61+
*
5862
* <ul>
5963
* <li><b>Numeric Types</b>:<br>
60-
* {@link java.lang.Byte Byte}, {@link java.lang.Double Double}, {@link java.lang.Float Float},
61-
* {@link java.lang.Integer Integer}, {@link java.lang.Long Long}, {@link java.lang.Short Short}
62-
* </li>
64+
* {@link java.lang.Byte Byte}, {@link java.lang.Double Double}, {@link java.lang.Float
65+
* Float}, {@link java.lang.Integer Integer}, {@link java.lang.Long Long}, {@link
66+
* java.lang.Short Short}
6367
* <li><b>Collection Types</b>:<br>
6468
* {@link java.util.List List}, {@link java.util.Set Set}
65-
* </li>
6669
* <li><b>Standard Java Types</b>:<br>
67-
* {@link java.util.Map Map}, {@link java.lang.Boolean Boolean}, {@link java.lang.String String},
68-
* {@link java.lang.Enum Enum}, {@link java.net.URI URI}, {@link java.net.URL URL},
69-
* {@link java.util.UUID UUID}, {@link java.time.Instant Instant}, {@link java.lang.Object Object}
70-
* </li>
70+
* {@link java.util.Map Map}, {@link java.lang.Boolean Boolean}, {@link java.lang.String
71+
* String}, {@link java.lang.Enum Enum}, {@link java.net.URI URI}, {@link java.net.URL URL},
72+
* {@link java.util.UUID UUID}, {@link java.time.Instant Instant}, {@link java.lang.Object
73+
* Object}
7174
* </ul>
7275
*
73-
* You can serialize objects for which no explicit coercer has been specified, and the <b>Json</b> API will use a
74-
* generic process to provide best-effort JSON output. For the most predictable results, though, it's best to
75-
* provide a {@code toJson()} method for the <b>Json</b> API to use for serialization. This is especially beneficial
76-
* for objects that contain transient properties that should be omitted from the JSON output.
77-
* <p>
78-
* You can deserialize objects for which no explicit handling has been defined. Note that the data type of the
79-
* result will be {@code Map<String,?>}, which means that you'll need to perform type checking and casting every
80-
* time you extract an entry value from the result. For this reason, it's best to declare a type-specific
81-
* {@code fromJson()} method in every type you need to deserialize.
76+
* You can serialize objects for which no explicit coercer has been specified, and the <b>Json</b>
77+
* API will use a generic process to provide best-effort JSON output. For the most predictable
78+
* results, though, it's best to provide a {@code toJson()} method for the <b>Json</b> API to use
79+
* for serialization. This is especially beneficial for objects that contain transient properties
80+
* that should be omitted from the JSON output.
81+
*
82+
* <p>You can deserialize objects for which no explicit handling has been defined. Note that the
83+
* data type of the result will be {@code Map<String,?>}, which means that you'll need to perform
84+
* type checking and casting every time you extract an entry value from the result. For this reason,
85+
* it's best to declare a type-specific {@code fromJson()} method in every type you need to
86+
* deserialize.
8287
*
8388
* @see JsonTypeCoercer
8489
* @see JsonInput
8590
* @see JsonOutput
8691
*/
8792
public class Json {
88-
/** The value of {@code Content-Type} headers for HTTP requests and
89-
* responses with JSON entities */
93+
/**
94+
* The value of {@code Content-Type} headers for HTTP requests and responses with JSON entities
95+
*/
9096
public static final String JSON_UTF_8 = "application/json; charset=utf-8";
9197

9298
/** Specifier for {@code List<Map<String, Object>} input/output type */
9399
public static final Type LIST_OF_MAPS_TYPE =
94-
new TypeToken<List<Map<String, Object>>>() {}.getType();
100+
new TypeToken<List<Map<String, Object>>>() {}.getType();
101+
95102
/** Specifier for {@code Map<String, Object>} input/output type */
96103
public static final Type MAP_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
104+
97105
/** Specifier for {@code Object} input/output type */
98106
public static final Type OBJECT_TYPE = new TypeToken<Object>() {}.getType();
99107

100108
private final JsonTypeCoercer fromJson = new JsonTypeCoercer();
101109

102110
/**
103111
* Serialize the specified object to JSON string representation.<br>
104-
* <b>NOTE</b>: This method limits traversal of nested objects to the default
105-
* {@link JsonOutput#MAX_DEPTH maximum depth}.
112+
* <b>NOTE</b>: This method limits traversal of nested objects to the default {@link
113+
* JsonOutput#MAX_DEPTH maximum depth}.
106114
*
107115
* @param toConvert the object to be serialized
108116
* @return JSON string representing the specified object
@@ -121,7 +129,7 @@ public String toJson(Object toConvert) {
121129
*/
122130
public String toJson(Object toConvert, int maxDepth) {
123131
try (Writer writer = new StringWriter();
124-
JsonOutput jsonOutput = newOutput(writer)) {
132+
JsonOutput jsonOutput = newOutput(writer)) {
125133
jsonOutput.write(toConvert, maxDepth);
126134
return writer.toString();
127135
} catch (IOException e) {
@@ -131,8 +139,8 @@ public String toJson(Object toConvert, int maxDepth) {
131139

132140
/**
133141
* Deserialize the specified JSON string into an object of the specified type.<br>
134-
* <b>NOTE</b>: This method uses the {@link PropertySetting#BY_NAME BY_NAME} strategy to assign values to properties
135-
* in the deserialized object.
142+
* <b>NOTE</b>: This method uses the {@link PropertySetting#BY_NAME BY_NAME} strategy to assign
143+
* values to properties in the deserialized object.
136144
*
137145
* @param source serialized source as JSON string
138146
* @param typeOfT data type for deserialization (class or {@link TypeToken})
@@ -163,9 +171,10 @@ public <T> T toType(String source, Type typeOfT, PropertySetting setter) {
163171
}
164172

165173
/**
166-
* Deserialize the JSON string supplied by the specified {@code Reader} into an object of the specified type.<br>
167-
* <b>NOTE</b>: This method uses the {@link PropertySetting#BY_NAME BY_NAME} strategy to assign values to properties
168-
* in the deserialized object.
174+
* Deserialize the JSON string supplied by the specified {@code Reader} into an object of the
175+
* specified type.<br>
176+
* <b>NOTE</b>: This method uses the {@link PropertySetting#BY_NAME BY_NAME} strategy to assign
177+
* values to properties in the deserialized object.
169178
*
170179
* @param source {@link Reader} that supplies a serialized JSON string
171180
* @param typeOfT data type for deserialization (class or {@link TypeToken})
@@ -178,7 +187,8 @@ public <T> T toType(Reader source, Type typeOfT) {
178187
}
179188

180189
/**
181-
* Deserialize the JSON string supplied by the specified {@code Reader} into an object of the specified type.
190+
* Deserialize the JSON string supplied by the specified {@code Reader} into an object of the
191+
* specified type.
182192
*
183193
* @param source {@link Reader} that supplies a serialized JSON string
184194
* @param typeOfT data type for deserialization (class or {@link TypeToken})
@@ -198,9 +208,11 @@ public <T> T toType(Reader source, Type typeOfT, PropertySetting setter) {
198208
}
199209

200210
/**
201-
* Create a new {@code JsonInput} object to traverse the JSON string supplied the specified {@code Reader}.<br>
202-
* <b>NOTE</b>: The {@code JsonInput} object returned by this method uses the {@link PropertySetting#BY_NAME BY_NAME}
203-
* strategy to assign values to properties objects it deserializes.
211+
* Create a new {@code JsonInput} object to traverse the JSON string supplied the specified {@code
212+
* Reader}.<br>
213+
* <b>NOTE</b>: The {@code JsonInput} object returned by this method uses the {@link
214+
* PropertySetting#BY_NAME BY_NAME} strategy to assign values to properties objects it
215+
* deserializes.
204216
*
205217
* @param from {@link Reader} that supplies a serialized JSON string
206218
* @return {@link JsonInput} object to traverse the JSON string supplied by [from]
@@ -211,7 +223,8 @@ public JsonInput newInput(Reader from) throws UncheckedIOException {
211223
}
212224

213225
/**
214-
* Create a new {@code JsonOutput} object to produce a serialized JSON string in the specified {@code Appendable}.
226+
* Create a new {@code JsonOutput} object to produce a serialized JSON string in the specified
227+
* {@code Appendable}.
215228
*
216229
* @param to {@link Appendable} that consumes a serialized JSON string
217230
* @return {@link JsonOutput} object to product a JSON string in [to]

java/src/org/openqa/selenium/json/JsonInput.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import org.openqa.selenium.internal.Require;
3232

3333
/**
34-
* The <b>JsonInput</b> class defines the operations used to deserialize JSON strings into Java objects.
34+
* The <b>JsonInput</b> class defines the operations used to deserialize JSON strings into Java
35+
* objects.
3536
*/
3637
public class JsonInput implements Closeable {
3738

@@ -51,7 +52,8 @@ public class JsonInput implements Closeable {
5152
* {@code Reader} object specified by [source].
5253
*
5354
* @param source {@link Reader} object that supplies the JSON string to be processed
54-
* @param coercer {@link JsonTypeCoercer} that encapsulates the defined type-specific deserializers
55+
* @param coercer {@link JsonTypeCoercer} that encapsulates the defined type-specific
56+
* deserializers
5557
* @param setter strategy used to assign values during deserialization
5658
*/
5759
JsonInput(Reader source, JsonTypeCoercer coercer, PropertySetting setter) {
@@ -200,7 +202,7 @@ public String nextName() {
200202
char read = input.read();
201203
if (read != ':') {
202204
throw new JsonException(
203-
"Unable to read name. Expected colon separator, but saw '" + read + "'");
205+
"Unable to read name. Expected colon separator, but saw '" + read + "'");
204206
}
205207
return name;
206208
}
@@ -232,11 +234,11 @@ public Number nextNumber() {
232234
do {
233235
char read = input.peek();
234236
if (Character.isDigit(read)
235-
|| read == '+'
236-
|| read == '-'
237-
|| read == 'e'
238-
|| read == 'E'
239-
|| read == '.') {
237+
|| read == '+'
238+
|| read == '-'
239+
|| read == 'e'
240+
|| read == 'E'
241+
|| read == '.') {
240242
builder.append(input.read());
241243
} else {
242244
break;
@@ -290,7 +292,7 @@ public Instant nextInstant() {
290292
public boolean hasNext() {
291293
if (stack.isEmpty()) {
292294
throw new JsonException(
293-
"Unable to determine if an item has next when not in a container type. " + input);
295+
"Unable to determine if an item has next when not in a container type. " + input);
294296
}
295297

296298
skipWhitespace(input);
@@ -325,7 +327,7 @@ public void endArray() {
325327
if (expectation != Container.COLLECTION) {
326328
// The only other thing we could be closing is a map
327329
throw new JsonException(
328-
"Attempt to close a JSON List, but a JSON Object was expected. " + input);
330+
"Attempt to close a JSON List, but a JSON Object was expected. " + input);
329331
}
330332
input.read();
331333
}
@@ -413,7 +415,7 @@ public void skipValue() {
413415
*
414416
* @param type data type for deserialization (class or {@link TypeToken})
415417
* @return object of the specified type deserialized from the JSON input stream<br>
416-
* <b>NOTE</b>: Returns {@code null} if the input string is exhausted.
418+
* <b>NOTE</b>: Returns {@code null} if the input string is exhausted.
417419
* @param <T> result type (as specified by [type])
418420
* @throws JsonException if coercion of the next element to the specified type fails
419421
* @throws UncheckedIOException if an I/O exception is encountered
@@ -448,7 +450,7 @@ private boolean isReadingName() {
448450
private void expect(JsonType type) {
449451
if (peek() != type) {
450452
throw new JsonException(
451-
"Expected to read a " + type + " but instead have: " + peek() + ". " + input);
453+
"Expected to read a " + type + " but instead have: " + peek() + ". " + input);
452454
}
453455

454456
// Special map handling. Woo!
@@ -474,7 +476,8 @@ private void expect(JsonType type) {
474476
}
475477

476478
/**
477-
* Read the next element from the JSON input stream, converting with the supplied mapper if it's the expected string.
479+
* Read the next element from the JSON input stream, converting with the supplied mapper if it's
480+
* the expected string.
478481
*
479482
* @param toCompare expected element string
480483
* @param mapper function to convert the element string to its corresponding type
@@ -489,8 +492,8 @@ private <X> X read(String toCompare, Function<String, X> mapper) {
489492
char read = input.read();
490493
if (read != toCompare.charAt(i)) {
491494
throw new JsonException(
492-
String.format(
493-
"Unable to read %s. Saw %s at position %d. %s", toCompare, read, i, input));
495+
String.format(
496+
"Unable to read %s. Saw %s at position %d. %s", toCompare, read, i, input));
494497
}
495498
}
496499

@@ -526,8 +529,8 @@ private String readString() {
526529
}
527530

528531
/**
529-
* Convert the escape sequence at the current JSON input stream position, appending the result to the provided
530-
* builder.
532+
* Convert the escape sequence at the current JSON input stream position, appending the result to
533+
* the provided builder.
531534
*
532535
* @param builder {@link StringBuilder}
533536
* @throws JsonException if an unsupported escape sequence is found
@@ -597,9 +600,7 @@ private void skipWhitespace(Input input) {
597600
}
598601
}
599602

600-
/**
601-
* Used to track the current container processing state.
602-
*/
603+
/** Used to track the current container processing state. */
603604
private enum Container {
604605

605606
/** Processing a JSON array */

0 commit comments

Comments
 (0)