Skip to content

Commit

Permalink
Fixes spelling in comments and removes compile time warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
John J. Aylward committed May 16, 2017
1 parent ae1e9e2 commit c870094
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CookieList.java
Expand Up @@ -39,7 +39,7 @@ public class CookieList {
* The pairs are separated by ';'. The names and the values
* will be unescaped, possibly converting '+' and '%' sequences.
*
* To add a cookie to a cooklist,
* To add a cookie to a cookie list,
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
* cookieJSONObject.getString("value"));
* @param string A cookie list string
Expand Down
7 changes: 4 additions & 3 deletions JSONArray.java
Expand Up @@ -183,7 +183,7 @@ public JSONArray(Object array) throws JSONException {

@Override
public Iterator<Object> iterator() {
return myArrayList.iterator();
return this.myArrayList.iterator();
}

/**
Expand Down Expand Up @@ -1115,6 +1115,7 @@ public JSONObject toJSONObject(JSONArray names) throws JSONException {
* @return a printable, displayable, transmittable representation of the
* array.
*/
@Override
public String toString() {
try {
return this.toString(0);
Expand All @@ -1124,7 +1125,7 @@ public String toString() {
}

/**
* Make a prettyprinted JSON text of this JSONArray. Warning: This method
* Make a pretty-printed JSON text of this JSONArray. Warning: This method
* assumes that the data structure is acyclical.
*
* @param indentFactor
Expand Down Expand Up @@ -1166,7 +1167,7 @@ public Writer write(Writer writer) throws JSONException {
* @param indentFactor
* The number of spaces to add to each level of indentation.
* @param indent
* The indention of the top level.
* The indentation of the top level.
* @return The writer.
* @throws JSONException
*/
Expand Down
52 changes: 39 additions & 13 deletions JSONObject.java
Expand Up @@ -126,6 +126,15 @@ protected final Object clone() {
public boolean equals(Object object) {
return object == null || object == this;
}
/**
* A Null object is equal to the null value and to itself.
*
* @return always returns 0.
*/
@Override
public int hashCode() {
return 0;
}

/**
* Get the "null" string value.
Expand Down Expand Up @@ -754,13 +763,13 @@ public JSONObject increment(String key) throws JSONException {
} else if (value instanceof BigDecimal) {
this.put(key, ((BigDecimal)value).add(BigDecimal.ONE));
} else if (value instanceof Integer) {
this.put(key, (Integer) value + 1);
this.put(key, ((Integer) value).intValue() + 1);
} else if (value instanceof Long) {
this.put(key, (Long) value + 1);
this.put(key, ((Long) value).longValue() + 1L);
} else if (value instanceof Double) {
this.put(key, (Double) value + 1);
this.put(key, ((Double) value).doubleValue() + 1D);
} else if (value instanceof Float) {
this.put(key, (Float) value + 1);
this.put(key, ((Float) value).floatValue() + 1F);
} else {
throw new JSONException("Unable to increment [" + quote(key) + "].");
}
Expand Down Expand Up @@ -887,7 +896,7 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
* @param defaultValue
* The default in case the value is not found
* @return The enum value associated with the key or defaultValue
* if the value is not found or cannot be assigned to clazz
* if the value is not found or cannot be assigned to <code>clazz</code>
*/
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key, E defaultValue) {
try {
Expand Down Expand Up @@ -1218,7 +1227,23 @@ public JSONObject put(String key, Collection<?> value) throws JSONException {
* If the key is null or if the number is invalid.
*/
public JSONObject put(String key, double value) throws JSONException {
this.put(key, new Double(value));
this.put(key, Double.valueOf(value));
return this;
}

/**
* Put a key/float pair in the JSONObject.
*
* @param key
* A key string.
* @param value
* A float which is the value.
* @return this.
* @throws JSONException
* If the key is null or if the number is invalid.
*/
public JSONObject put(String key, float value) throws JSONException {
this.put(key, Float.valueOf(value));
return this;
}

Expand All @@ -1234,7 +1259,7 @@ public JSONObject put(String key, double value) throws JSONException {
* If the key is null.
*/
public JSONObject put(String key, int value) throws JSONException {
this.put(key, new Integer(value));
this.put(key, Integer.valueOf(value));
return this;
}

Expand All @@ -1250,7 +1275,7 @@ public JSONObject put(String key, int value) throws JSONException {
* If the key is null.
*/
public JSONObject put(String key, long value) throws JSONException {
this.put(key, new Long(value));
this.put(key, Long.valueOf(value));
return this;
}

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

/**
* Creates a JSONPointer using an intialization string and tries to
* Creates a JSONPointer using an initialization string and tries to
* match it to an item within this JSONObject. For example, given a
* JSONObject initialized with this document:
* <pre>
Expand All @@ -1362,7 +1387,7 @@ public Object query(String jsonPointer) {
return query(new JSONPointer(jsonPointer));
}
/**
* Uses a uaer initialized JSONPointer and tries to
* Uses a user initialized JSONPointer and tries to
* match it to an item within this JSONObject. For example, given a
* JSONObject initialized with this document:
* <pre>
Expand Down Expand Up @@ -1665,7 +1690,7 @@ public String toString() {
}

/**
* Make a prettyprinted JSON text of this JSONObject.
* Make a pretty-printed JSON text of this JSONObject.
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
Expand Down Expand Up @@ -1730,7 +1755,8 @@ public static String valueToString(Object value) throws JSONException {
final String numberAsString = numberToString((Number) value);
try {
// Use the BigDecimal constructor for it's parser to validate the format.
new BigDecimal(numberAsString);
@SuppressWarnings("unused")
BigDecimal unused = new BigDecimal(numberAsString);
// Close enough to a JSON number that we will return it unquoted
return numberAsString;
} catch (NumberFormatException ex){
Expand Down Expand Up @@ -1891,7 +1917,7 @@ static final void indent(Writer writer, int indent) throws IOException {
* @param indentFactor
* The number of spaces to add to each level of indentation.
* @param indent
* The indention of the top level.
* The indentation of the top level.
* @return The writer.
* @throws JSONException
*/
Expand Down
34 changes: 18 additions & 16 deletions JSONPointer.java
Expand Up @@ -68,11 +68,11 @@ public static class Builder {
* {@link #append(String)} method calls.
*/
public JSONPointer build() {
return new JSONPointer(refTokens);
return new JSONPointer(this.refTokens);
}

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

Expand All @@ -99,7 +99,7 @@ public Builder append(String token) {
* @return {@code this}
*/
public Builder append(int arrayIndex) {
refTokens.add(String.valueOf(arrayIndex));
this.refTokens.add(String.valueOf(arrayIndex));
return this;
}
}
Expand Down Expand Up @@ -134,29 +134,30 @@ public static Builder builder() {
* @param pointer the JSON String or URI Fragment representation of the JSON pointer.
* @throws IllegalArgumentException if {@code pointer} is not a valid JSON pointer
*/
public JSONPointer(String pointer) {
public JSONPointer(final String pointer) {
if (pointer == null) {
throw new NullPointerException("pointer cannot be null");
}
if (pointer.isEmpty() || pointer.equals("#")) {
refTokens = Collections.emptyList();
this.refTokens = Collections.emptyList();
return;
}
String refs;
if (pointer.startsWith("#/")) {
pointer = pointer.substring(2);
refs = pointer.substring(2);
try {
pointer = URLDecoder.decode(pointer, ENCODING);
refs = URLDecoder.decode(refs, ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else if (pointer.startsWith("/")) {
pointer = pointer.substring(1);
refs = pointer.substring(1);
} else {
throw new IllegalArgumentException("a JSON pointer should start with '/' or '#/'");
}
refTokens = new ArrayList<String>();
for (String token : pointer.split("/")) {
refTokens.add(unescape(token));
this.refTokens = new ArrayList<String>();
for (String token : refs.split("/")) {
this.refTokens.add(unescape(token));
}
}

Expand All @@ -181,11 +182,11 @@ private String unescape(String token) {
* @throws JSONPointerException if an error occurs during evaluation
*/
public Object queryFrom(Object document) {
if (refTokens.isEmpty()) {
if (this.refTokens.isEmpty()) {
return document;
}
Object current = document;
for (String token : refTokens) {
for (String token : this.refTokens) {
if (current instanceof JSONObject) {
current = ((JSONObject) current).opt(unescape(token));
} else if (current instanceof JSONArray) {
Expand All @@ -206,6 +207,7 @@ public Object queryFrom(Object document) {
* @return the matched object. If no matching item is found a
* JSONPointerException is thrown
*/
@SuppressWarnings("boxing")
private Object readByIndexToken(Object current, String indexToken) {
try {
int index = Integer.parseInt(indexToken);
Expand All @@ -227,7 +229,7 @@ private Object readByIndexToken(Object current, String indexToken) {
@Override
public String toString() {
StringBuilder rval = new StringBuilder("");
for (String token: refTokens) {
for (String token: this.refTokens) {
rval.append('/').append(escape(token));
}
return rval.toString();
Expand Down Expand Up @@ -255,7 +257,7 @@ private String escape(String token) {
public String toURIFragment() {
try {
StringBuilder rval = new StringBuilder("#");
for (String token : refTokens) {
for (String token : this.refTokens) {
rval.append('/').append(URLEncoder.encode(token, ENCODING));
}
return rval.toString();
Expand Down
1 change: 1 addition & 0 deletions JSONStringer.java
Expand Up @@ -72,6 +72,7 @@ public JSONStringer() {
* <code>endArray</code>).
* @return The JSON text.
*/
@Override
public String toString() {
return this.mode == 'd' ? this.writer.toString() : null;
}
Expand Down
10 changes: 5 additions & 5 deletions JSONWriter.java
Expand Up @@ -149,18 +149,18 @@ public JSONWriter array() throws JSONException {

/**
* End something.
* @param mode Mode
* @param m Mode
* @param c Closing character
* @return this
* @throws JSONException If unbalanced.
*/
private JSONWriter end(char mode, char c) throws JSONException {
if (this.mode != mode) {
throw new JSONException(mode == 'a'
private JSONWriter end(char m, char c) throws JSONException {
if (this.mode != m) {
throw new JSONException(m == 'a'
? "Misplaced endArray."
: "Misplaced endObject.");
}
this.pop(mode);
this.pop(m);
try {
this.writer.append(c);
} catch (IOException e) {
Expand Down
30 changes: 14 additions & 16 deletions XML.java
Expand Up @@ -211,15 +211,15 @@ public static String unescape(String string) {
sb.append('<');
} else if ("gt".equalsIgnoreCase(entity)) {
sb.append('>');
} else {
} else {// unsupported xml entity. leave encoded
sb.append('&').append(entity).append(';');
}
}
// skip past the entity we just parsed.
i += entity.length() + 1;
} else {
// this shouldn't happen in most cases since the parser
// errors on unclosed enties.
// errors on unclosed entries.
sb.append(c);
}
} else {
Expand Down Expand Up @@ -508,7 +508,7 @@ public static String toString(Object object) throws JSONException {
* @return A string.
* @throws JSONException Thrown if there is an error parsing the string
*/
public static String toString(Object object, String tagName)
public static String toString(final Object object, final String tagName)
throws JSONException {
StringBuilder sb = new StringBuilder();
JSONArray ja;
Expand Down Expand Up @@ -595,21 +595,19 @@ public static String toString(Object object, String tagName)

}

if (object != null) {
if (object.getClass().isArray()) {
object = new JSONArray(object);
}

if (object instanceof JSONArray) {
if (object != null && (object instanceof JSONArray || object.getClass().isArray())) {
if(object.getClass().isArray()) {
ja = new JSONArray(object);
} else {
ja = (JSONArray) object;
for (Object val : ja) {
// XML does not have good support for arrays. If an array
// appears in a place where XML is lacking, synthesize an
// <array> element.
sb.append(toString(val, tagName == null ? "array" : tagName));
}
return sb.toString();
}
for (Object val : ja) {
// XML does not have good support for arrays. If an array
// appears in a place where XML is lacking, synthesize an
// <array> element.
sb.append(toString(val, tagName == null ? "array" : tagName));
}
return sb.toString();
}

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

0 comments on commit c870094

Please sign in to comment.