From f63d21fd13cd76e005247b7676be632d3e856435 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 26 Jul 2019 15:23:31 -0700 Subject: [PATCH] Make private methods static where possible This avoids an unneeded object reference. Found via error-prone. --- JSONObject.java | 4 ++-- JSONPointer.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index a1ed4901c..c54018e15 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -1496,11 +1496,11 @@ && isValidMethodName(method.getName())) { } } - private boolean isValidMethodName(String name) { + private static boolean isValidMethodName(String name) { return !"getClass".equals(name) && !"getDeclaringClass".equals(name); } - private String getKeyNameFromMethod(Method method) { + private static String getKeyNameFromMethod(Method method) { final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class); if (ignoreDepth > 0) { final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class); diff --git a/JSONPointer.java b/JSONPointer.java index df06f22ed..d122fd840 100644 --- a/JSONPointer.java +++ b/JSONPointer.java @@ -186,7 +186,7 @@ public JSONPointer(List refTokens) { this.refTokens = new ArrayList(refTokens); } - private String unescape(String token) { + private static String unescape(String token) { return token.replace("~1", "/").replace("~0", "~") .replace("\\\"", "\"") .replace("\\\\", "\\"); @@ -228,7 +228,7 @@ public Object queryFrom(Object document) throws JSONPointerException { * @return the matched object. If no matching item is found a * @throws JSONPointerException is thrown if the index is out of bounds */ - private Object readByIndexToken(Object current, String indexToken) throws JSONPointerException { + private static Object readByIndexToken(Object current, String indexToken) throws JSONPointerException { try { int index = Integer.parseInt(indexToken); JSONArray currentArr = (JSONArray) current; @@ -267,7 +267,7 @@ public String toString() { * @param token the JSONPointer segment value to be escaped * @return the escaped value for the token */ - private String escape(String token) { + private static String escape(String token) { return token.replace("~", "~0") .replace("/", "~1") .replace("\\", "\\\\")