Skip to content

Commit

Permalink
Code cleanups.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Aug 2, 2021
1 parent 9705e05 commit 30a4257
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions jetty-util-ajax/src/main/java/org/eclipse/jetty/util/ajax/JSON.java
Expand Up @@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -91,7 +92,7 @@ public class JSON
static final Logger LOG = Log.getLogger(JSON.class);
public static final JSON DEFAULT = new JSON();

private Map<String, Convertor> _convertors = new ConcurrentHashMap<String, Convertor>();
private final Map<String, Convertor> _convertors = new ConcurrentHashMap<>();
private int _stringBufferSize = 1024;

public JSON()
Expand Down Expand Up @@ -307,13 +308,13 @@ else if (c < 0x20 || c == 0x7F) // all control characters
* This overridable allows for alternate behavior to escape those with your choice
* of encoding.
*
* <code>
* <pre>
* protected void escapeUnicode(Appendable buffer, char c) throws IOException
* {
* // Unicode is slash-u escaped
* buffer.append(String.format("\\u%04x", (int)c));
* // Unicode is slash-u escaped
* buffer.append(String.format("\\u%04x", (int)c));
* }
* </code>
* </pre>
*/
protected void escapeUnicode(Appendable buffer, char c) throws IOException
{
Expand Down Expand Up @@ -665,7 +666,7 @@ protected String toString(char[] buffer, int offset, int length)

protected Map<String, Object> newMap()
{
return new HashMap<String, Object>();
return new HashMap<>();
}

protected Object[] newArray(int size)
Expand Down Expand Up @@ -739,7 +740,7 @@ protected Convertor getConvertor(Class forClass)
{
Class[] ifs = cls.getInterfaces();
int i = 0;
while (convertor == null && ifs != null && i < ifs.length)
while (convertor == null && i < ifs.length)
{
convertor = _convertors.get(ifs[i++].getName());
}
Expand Down Expand Up @@ -1014,7 +1015,7 @@ protected Object parseObject(Source source)
{
try
{
Class c = Loader.loadClass(classname);
Class<?> c = Loader.loadClass(classname);
return convertTo(c, map);
}
catch (ClassNotFoundException e)
Expand All @@ -1032,9 +1033,9 @@ protected Object parseArray(Source source)
throw new IllegalStateException();

int size = 0;
ArrayList list = null;
List<Object> list = null;
Object item = null;
boolean coma = true;
boolean comma = true;

while (source.hasNext())
{
Expand All @@ -1056,23 +1057,27 @@ protected Object parseArray(Source source)
}

case ',':
if (coma)
if (comma)
throw new IllegalStateException();
coma = true;
comma = true;
source.next();
break;

default:
if (Character.isWhitespace(c))
{
source.next();
}
else
{
coma = false;
comma = false;
if (size++ == 0)
{
item = contextForArray().parse(source);
}
else if (list == null)
{
list = new ArrayList();
list = new ArrayList<>();
list.add(item);
item = contextForArray().parse(source);
list.add(item);
Expand All @@ -1085,6 +1090,7 @@ else if (list == null)
item = null;
}
}
break;
}
}

Expand Down Expand Up @@ -1319,7 +1325,7 @@ public Number parseNumber(Source source)
break doubleLoop;
}
}
return new Double(buffer.toString());
return Double.valueOf(buffer.toString());
}

protected void seekTo(char seek, Source source)
Expand Down Expand Up @@ -1696,7 +1702,7 @@ public interface Generator
*/
public static class Literal implements Generator
{
private String _json;
private final String _json;

/**
* Construct a literal JSON instance for use by
Expand Down

0 comments on commit 30a4257

Please sign in to comment.