Skip to content

Commit c870094

Browse files
author
John J. Aylward
committed
Fixes spelling in comments and removes compile time warnings
1 parent ae1e9e2 commit c870094

File tree

7 files changed

+82
-54
lines changed

7 files changed

+82
-54
lines changed

CookieList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class CookieList {
3939
* The pairs are separated by ';'. The names and the values
4040
* will be unescaped, possibly converting '+' and '%' sequences.
4141
*
42-
* To add a cookie to a cooklist,
42+
* To add a cookie to a cookie list,
4343
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
4444
* cookieJSONObject.getString("value"));
4545
* @param string A cookie list string

JSONArray.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public JSONArray(Object array) throws JSONException {
183183

184184
@Override
185185
public Iterator<Object> iterator() {
186-
return myArrayList.iterator();
186+
return this.myArrayList.iterator();
187187
}
188188

189189
/**
@@ -1115,6 +1115,7 @@ public JSONObject toJSONObject(JSONArray names) throws JSONException {
11151115
* @return a printable, displayable, transmittable representation of the
11161116
* array.
11171117
*/
1118+
@Override
11181119
public String toString() {
11191120
try {
11201121
return this.toString(0);
@@ -1124,7 +1125,7 @@ public String toString() {
11241125
}
11251126

11261127
/**
1127-
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
1128+
* Make a pretty-printed JSON text of this JSONArray. Warning: This method
11281129
* assumes that the data structure is acyclical.
11291130
*
11301131
* @param indentFactor
@@ -1166,7 +1167,7 @@ public Writer write(Writer writer) throws JSONException {
11661167
* @param indentFactor
11671168
* The number of spaces to add to each level of indentation.
11681169
* @param indent
1169-
* The indention of the top level.
1170+
* The indentation of the top level.
11701171
* @return The writer.
11711172
* @throws JSONException
11721173
*/

JSONObject.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ protected final Object clone() {
126126
public boolean equals(Object object) {
127127
return object == null || object == this;
128128
}
129+
/**
130+
* A Null object is equal to the null value and to itself.
131+
*
132+
* @return always returns 0.
133+
*/
134+
@Override
135+
public int hashCode() {
136+
return 0;
137+
}
129138

130139
/**
131140
* Get the "null" string value.
@@ -754,13 +763,13 @@ public JSONObject increment(String key) throws JSONException {
754763
} else if (value instanceof BigDecimal) {
755764
this.put(key, ((BigDecimal)value).add(BigDecimal.ONE));
756765
} else if (value instanceof Integer) {
757-
this.put(key, (Integer) value + 1);
766+
this.put(key, ((Integer) value).intValue() + 1);
758767
} else if (value instanceof Long) {
759-
this.put(key, (Long) value + 1);
768+
this.put(key, ((Long) value).longValue() + 1L);
760769
} else if (value instanceof Double) {
761-
this.put(key, (Double) value + 1);
770+
this.put(key, ((Double) value).doubleValue() + 1D);
762771
} else if (value instanceof Float) {
763-
this.put(key, (Float) value + 1);
772+
this.put(key, ((Float) value).floatValue() + 1F);
764773
} else {
765774
throw new JSONException("Unable to increment [" + quote(key) + "].");
766775
}
@@ -887,7 +896,7 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
887896
* @param defaultValue
888897
* The default in case the value is not found
889898
* @return The enum value associated with the key or defaultValue
890-
* if the value is not found or cannot be assigned to clazz
899+
* if the value is not found or cannot be assigned to <code>clazz</code>
891900
*/
892901
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key, E defaultValue) {
893902
try {
@@ -1218,7 +1227,23 @@ public JSONObject put(String key, Collection<?> value) throws JSONException {
12181227
* If the key is null or if the number is invalid.
12191228
*/
12201229
public JSONObject put(String key, double value) throws JSONException {
1221-
this.put(key, new Double(value));
1230+
this.put(key, Double.valueOf(value));
1231+
return this;
1232+
}
1233+
1234+
/**
1235+
* Put a key/float pair in the JSONObject.
1236+
*
1237+
* @param key
1238+
* A key string.
1239+
* @param value
1240+
* A float which is the value.
1241+
* @return this.
1242+
* @throws JSONException
1243+
* If the key is null or if the number is invalid.
1244+
*/
1245+
public JSONObject put(String key, float value) throws JSONException {
1246+
this.put(key, Float.valueOf(value));
12221247
return this;
12231248
}
12241249

@@ -1234,7 +1259,7 @@ public JSONObject put(String key, double value) throws JSONException {
12341259
* If the key is null.
12351260
*/
12361261
public JSONObject put(String key, int value) throws JSONException {
1237-
this.put(key, new Integer(value));
1262+
this.put(key, Integer.valueOf(value));
12381263
return this;
12391264
}
12401265

@@ -1250,7 +1275,7 @@ public JSONObject put(String key, int value) throws JSONException {
12501275
* If the key is null.
12511276
*/
12521277
public JSONObject put(String key, long value) throws JSONException {
1253-
this.put(key, new Long(value));
1278+
this.put(key, Long.valueOf(value));
12541279
return this;
12551280
}
12561281

@@ -1340,7 +1365,7 @@ public JSONObject putOpt(String key, Object value) throws JSONException {
13401365
}
13411366

13421367
/**
1343-
* Creates a JSONPointer using an intialization string and tries to
1368+
* Creates a JSONPointer using an initialization string and tries to
13441369
* match it to an item within this JSONObject. For example, given a
13451370
* JSONObject initialized with this document:
13461371
* <pre>
@@ -1362,7 +1387,7 @@ public Object query(String jsonPointer) {
13621387
return query(new JSONPointer(jsonPointer));
13631388
}
13641389
/**
1365-
* Uses a uaer initialized JSONPointer and tries to
1390+
* Uses a user initialized JSONPointer and tries to
13661391
* match it to an item within this JSONObject. For example, given a
13671392
* JSONObject initialized with this document:
13681393
* <pre>
@@ -1665,7 +1690,7 @@ public String toString() {
16651690
}
16661691

16671692
/**
1668-
* Make a prettyprinted JSON text of this JSONObject.
1693+
* Make a pretty-printed JSON text of this JSONObject.
16691694
* <p>
16701695
* Warning: This method assumes that the data structure is acyclical.
16711696
*
@@ -1730,7 +1755,8 @@ public static String valueToString(Object value) throws JSONException {
17301755
final String numberAsString = numberToString((Number) value);
17311756
try {
17321757
// Use the BigDecimal constructor for it's parser to validate the format.
1733-
new BigDecimal(numberAsString);
1758+
@SuppressWarnings("unused")
1759+
BigDecimal unused = new BigDecimal(numberAsString);
17341760
// Close enough to a JSON number that we will return it unquoted
17351761
return numberAsString;
17361762
} catch (NumberFormatException ex){
@@ -1891,7 +1917,7 @@ static final void indent(Writer writer, int indent) throws IOException {
18911917
* @param indentFactor
18921918
* The number of spaces to add to each level of indentation.
18931919
* @param indent
1894-
* The indention of the top level.
1920+
* The indentation of the top level.
18951921
* @return The writer.
18961922
* @throws JSONException
18971923
*/

JSONPointer.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public static class Builder {
6868
* {@link #append(String)} method calls.
6969
*/
7070
public JSONPointer build() {
71-
return new JSONPointer(refTokens);
71+
return new JSONPointer(this.refTokens);
7272
}
7373

7474
/**
75-
* Adds an arbitary token to the list of reference tokens. It can be any non-null value.
75+
* Adds an arbitrary token to the list of reference tokens. It can be any non-null value.
7676
*
7777
* Unlike in the case of JSON string or URI fragment representation of JSON pointers, the
7878
* argument of this method MUST NOT be escaped. If you want to query the property called
@@ -87,7 +87,7 @@ public Builder append(String token) {
8787
if (token == null) {
8888
throw new NullPointerException("token cannot be null");
8989
}
90-
refTokens.add(token);
90+
this.refTokens.add(token);
9191
return this;
9292
}
9393

@@ -99,7 +99,7 @@ public Builder append(String token) {
9999
* @return {@code this}
100100
*/
101101
public Builder append(int arrayIndex) {
102-
refTokens.add(String.valueOf(arrayIndex));
102+
this.refTokens.add(String.valueOf(arrayIndex));
103103
return this;
104104
}
105105
}
@@ -134,29 +134,30 @@ public static Builder builder() {
134134
* @param pointer the JSON String or URI Fragment representation of the JSON pointer.
135135
* @throws IllegalArgumentException if {@code pointer} is not a valid JSON pointer
136136
*/
137-
public JSONPointer(String pointer) {
137+
public JSONPointer(final String pointer) {
138138
if (pointer == null) {
139139
throw new NullPointerException("pointer cannot be null");
140140
}
141141
if (pointer.isEmpty() || pointer.equals("#")) {
142-
refTokens = Collections.emptyList();
142+
this.refTokens = Collections.emptyList();
143143
return;
144144
}
145+
String refs;
145146
if (pointer.startsWith("#/")) {
146-
pointer = pointer.substring(2);
147+
refs = pointer.substring(2);
147148
try {
148-
pointer = URLDecoder.decode(pointer, ENCODING);
149+
refs = URLDecoder.decode(refs, ENCODING);
149150
} catch (UnsupportedEncodingException e) {
150151
throw new RuntimeException(e);
151152
}
152153
} else if (pointer.startsWith("/")) {
153-
pointer = pointer.substring(1);
154+
refs = pointer.substring(1);
154155
} else {
155156
throw new IllegalArgumentException("a JSON pointer should start with '/' or '#/'");
156157
}
157-
refTokens = new ArrayList<String>();
158-
for (String token : pointer.split("/")) {
159-
refTokens.add(unescape(token));
158+
this.refTokens = new ArrayList<String>();
159+
for (String token : refs.split("/")) {
160+
this.refTokens.add(unescape(token));
160161
}
161162
}
162163

@@ -181,11 +182,11 @@ private String unescape(String token) {
181182
* @throws JSONPointerException if an error occurs during evaluation
182183
*/
183184
public Object queryFrom(Object document) {
184-
if (refTokens.isEmpty()) {
185+
if (this.refTokens.isEmpty()) {
185186
return document;
186187
}
187188
Object current = document;
188-
for (String token : refTokens) {
189+
for (String token : this.refTokens) {
189190
if (current instanceof JSONObject) {
190191
current = ((JSONObject) current).opt(unescape(token));
191192
} else if (current instanceof JSONArray) {
@@ -206,6 +207,7 @@ public Object queryFrom(Object document) {
206207
* @return the matched object. If no matching item is found a
207208
* JSONPointerException is thrown
208209
*/
210+
@SuppressWarnings("boxing")
209211
private Object readByIndexToken(Object current, String indexToken) {
210212
try {
211213
int index = Integer.parseInt(indexToken);
@@ -227,7 +229,7 @@ private Object readByIndexToken(Object current, String indexToken) {
227229
@Override
228230
public String toString() {
229231
StringBuilder rval = new StringBuilder("");
230-
for (String token: refTokens) {
232+
for (String token: this.refTokens) {
231233
rval.append('/').append(escape(token));
232234
}
233235
return rval.toString();
@@ -255,7 +257,7 @@ private String escape(String token) {
255257
public String toURIFragment() {
256258
try {
257259
StringBuilder rval = new StringBuilder("#");
258-
for (String token : refTokens) {
260+
for (String token : this.refTokens) {
259261
rval.append('/').append(URLEncoder.encode(token, ENCODING));
260262
}
261263
return rval.toString();

JSONStringer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public JSONStringer() {
7272
* <code>endArray</code>).
7373
* @return The JSON text.
7474
*/
75+
@Override
7576
public String toString() {
7677
return this.mode == 'd' ? this.writer.toString() : null;
7778
}

JSONWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,18 @@ public JSONWriter array() throws JSONException {
149149

150150
/**
151151
* End something.
152-
* @param mode Mode
152+
* @param m Mode
153153
* @param c Closing character
154154
* @return this
155155
* @throws JSONException If unbalanced.
156156
*/
157-
private JSONWriter end(char mode, char c) throws JSONException {
158-
if (this.mode != mode) {
159-
throw new JSONException(mode == 'a'
157+
private JSONWriter end(char m, char c) throws JSONException {
158+
if (this.mode != m) {
159+
throw new JSONException(m == 'a'
160160
? "Misplaced endArray."
161161
: "Misplaced endObject.");
162162
}
163-
this.pop(mode);
163+
this.pop(m);
164164
try {
165165
this.writer.append(c);
166166
} catch (IOException e) {

XML.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,15 @@ public static String unescape(String string) {
211211
sb.append('<');
212212
} else if ("gt".equalsIgnoreCase(entity)) {
213213
sb.append('>');
214-
} else {
214+
} else {// unsupported xml entity. leave encoded
215215
sb.append('&').append(entity).append(';');
216216
}
217217
}
218218
// skip past the entity we just parsed.
219219
i += entity.length() + 1;
220220
} else {
221221
// this shouldn't happen in most cases since the parser
222-
// errors on unclosed enties.
222+
// errors on unclosed entries.
223223
sb.append(c);
224224
}
225225
} else {
@@ -508,7 +508,7 @@ public static String toString(Object object) throws JSONException {
508508
* @return A string.
509509
* @throws JSONException Thrown if there is an error parsing the string
510510
*/
511-
public static String toString(Object object, String tagName)
511+
public static String toString(final Object object, final String tagName)
512512
throws JSONException {
513513
StringBuilder sb = new StringBuilder();
514514
JSONArray ja;
@@ -595,21 +595,19 @@ public static String toString(Object object, String tagName)
595595

596596
}
597597

598-
if (object != null) {
599-
if (object.getClass().isArray()) {
600-
object = new JSONArray(object);
601-
}
602-
603-
if (object instanceof JSONArray) {
598+
if (object != null && (object instanceof JSONArray || object.getClass().isArray())) {
599+
if(object.getClass().isArray()) {
600+
ja = new JSONArray(object);
601+
} else {
604602
ja = (JSONArray) object;
605-
for (Object val : ja) {
606-
// XML does not have good support for arrays. If an array
607-
// appears in a place where XML is lacking, synthesize an
608-
// <array> element.
609-
sb.append(toString(val, tagName == null ? "array" : tagName));
610-
}
611-
return sb.toString();
612603
}
604+
for (Object val : ja) {
605+
// XML does not have good support for arrays. If an array
606+
// appears in a place where XML is lacking, synthesize an
607+
// <array> element.
608+
sb.append(toString(val, tagName == null ? "array" : tagName));
609+
}
610+
return sb.toString();
613611
}
614612

615613
string = (object == null) ? "null" : escape(object.toString());

0 commit comments

Comments
 (0)