You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2016/04/24 18:16:43 UTC

[1/3] groovy git commit: refactor(json): remove final modifier from private methods

Repository: groovy
Updated Branches:
  refs/heads/master e9f282fc4 -> 2cdba2f01


refactor(json): remove final modifier from private methods

Since private methods cannot be meaningfully overridden, declaring them final is redundant and can be confusing to those reviewing the code.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f58421eb
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f58421eb
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f58421eb

Branch: refs/heads/master
Commit: f58421ebb56663d99be4ad0c0fe8348ef7ce7b71
Parents: e9f282f
Author: John Wagenleitner <jw...@apache.org>
Authored: Fri Apr 22 22:53:51 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sun Apr 24 09:04:53 2016 -0700

----------------------------------------------------------------------
 .../src/main/java/groovy/json/internal/CharBuf.java            | 6 +++---
 .../src/main/java/groovy/json/internal/CharSequenceValue.java  | 2 +-
 .../src/main/java/groovy/json/internal/JsonFastParser.java     | 2 +-
 .../main/java/groovy/json/internal/JsonParserCharArray.java    | 4 ++--
 .../groovy/json/internal/JsonParserUsingCharacterSource.java   | 4 ++--
 .../src/main/java/groovy/json/internal/LazyValueMap.java       | 2 +-
 .../src/main/java/groovy/json/internal/NumberValue.java        | 2 +-
 .../src/main/java/groovy/json/internal/ValueMapImpl.java       | 2 +-
 8 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
index 790b19f..8491498 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
@@ -386,7 +386,7 @@ public class CharBuf extends Writer implements CharSequence {
 
     final byte[] charTo = new byte[2];
 
-    private final CharBuf doAddJsonEscapedString(char[] charArray) {
+    private CharBuf doAddJsonEscapedString(char[] charArray) {
         char[] _buffer = buffer;
         int _location = this.location;
 
@@ -558,11 +558,11 @@ public class CharBuf extends Writer implements CharSequence {
         return this;
     }
 
-    private static final void sysstemarraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
+    private static void sysstemarraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
         System.arraycopy(src, srcPos, dest, destPos, length);
     }
 
-    private static final void arraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
+    private static void arraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
         sysstemarraycopy(src, srcPos, dest, destPos, length);
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
index ab33c26..6ec6220 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
@@ -113,7 +113,7 @@ public class CharSequenceValue implements Value, CharSequence {
         return false;
     }
 
-    private final Object doToValue() {
+    private Object doToValue() {
         switch (type) {
             case DOUBLE:
                 return doubleValue();

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
index c088b4d..cc90a4d 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
@@ -155,7 +155,7 @@ public class JsonFastParser extends JsonParserCharArray {
         }
     }
 
-    private final Value decodeNumberOverlay(final boolean minus) {
+    private Value decodeNumberOverlay(final boolean minus) {
         char[] array = charArray;
 
         final int startIndex = __index;

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
index f716d97..6bb55b8 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
@@ -158,7 +158,7 @@ public class JsonParserCharArray extends BaseJsonParser {
         return decodeValueInternal();
     }
 
-    private final Object decodeValueInternal() {
+    private Object decodeValueInternal() {
         Object value = null;
         skipWhiteSpace();
 
@@ -213,7 +213,7 @@ public class JsonParserCharArray extends BaseJsonParser {
 
     int[] endIndex = new int[1];
 
-    private final Object decodeNumber() {
+    private Object decodeNumber() {
         Number num = CharScanner.parseJsonNumber(charArray, __index, charArray.length, endIndex);
         __index = endIndex[0];
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserUsingCharacterSource.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserUsingCharacterSource.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserUsingCharacterSource.java
index 0678f68..47a470f 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserUsingCharacterSource.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserUsingCharacterSource.java
@@ -108,7 +108,7 @@ public class JsonParserUsingCharacterSource extends BaseJsonParser {
         throw new JsonException(exceptionDetails(complaint));
     }
 
-    private final Object decodeValue() {
+    private Object decodeValue() {
         CharacterSource characterSource = this.characterSource;
         Object value = null;
         characterSource.skipWhiteSpace();
@@ -163,7 +163,7 @@ public class JsonParserUsingCharacterSource extends BaseJsonParser {
         return value;
     }
 
-    private final Object decodeNumber(boolean negative) {
+    private Object decodeNumber(boolean negative) {
         char[] chars = characterSource.readNumber();
         Object value = null;
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/LazyValueMap.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/LazyValueMap.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/LazyValueMap.java
index 639c464..91dea6e 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/LazyValueMap.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/LazyValueMap.java
@@ -194,7 +194,7 @@ public class LazyValueMap extends AbstractMap<String, Object> implements ValueMa
         return map.entrySet();
     }
 
-    private final void buildMap() {
+    private void buildMap() {
         /** added to avoid hash collision attack. */
         if (Sys.is1_7OrLater() && System.getProperty("jdk.map.althashing.threshold") != null) {
             map = new HashMap<String, Object>(items.length);

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
index fe543ab..ceb9864 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
@@ -99,7 +99,7 @@ public class NumberValue extends java.lang.Number implements Value {
         return false;
     }
 
-    private final Object doToValue() {
+    private Object doToValue() {
         switch (type) {
             case DOUBLE:
                 return bigDecimalValue();

http://git-wip-us.apache.org/repos/asf/groovy/blob/f58421eb/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java
index 8c77b1f..b2a7cfa 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/ValueMapImpl.java
@@ -110,7 +110,7 @@ public class ValueMapImpl extends AbstractMap<String, Value> implements ValueMap
     /**
      * Build the map if requested to, it does this lazily.
      */
-    private final void buildIfNeededMap() {
+    private void buildIfNeededMap() {
         if (map == null) {
             map = new HashMap<String, Value>(items.length);
 


[2/3] groovy git commit: refactor(json): simplified expressions

Posted by jw...@apache.org.
refactor(json): simplified expressions


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7d9af963
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7d9af963
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7d9af963

Branch: refs/heads/master
Commit: 7d9af96369c9e3b1bda9a5eff14eb6a27816ac5b
Parents: f58421e
Author: John Wagenleitner <jw...@apache.org>
Authored: Fri Apr 22 23:04:11 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sun Apr 24 09:04:54 2016 -0700

----------------------------------------------------------------------
 .../groovy/json/internal/BaseJsonParser.java    | 10 +---------
 .../main/java/groovy/json/internal/CharBuf.java | 12 ++----------
 .../groovy/json/internal/CharSequenceValue.java |  3 +--
 .../main/java/groovy/json/internal/Dates.java   | 20 ++++++--------------
 .../groovy/json/internal/JsonFastParser.java    |  8 +++-----
 .../json/internal/JsonParserCharArray.java      |  6 ++----
 .../groovy/json/internal/JsonParserLax.java     | 14 ++++----------
 .../java/groovy/json/internal/NumberValue.java  |  3 +--
 .../json/internal/ReaderCharacterSource.java    |  4 +---
 .../main/java/groovy/json/internal/Value.java   |  2 +-
 10 files changed, 22 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
index 0f23e41..03e94de 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
@@ -213,15 +213,7 @@ public abstract class BaseJsonParser implements JsonParser {
                     break;
                 }
             }
-            if (isEscape(currentChar)) {
-                if (!escape) {
-                    escape = true;
-                } else {
-                    escape = false;
-                }
-            } else {
-                escape = false;
-            }
+            escape = isEscape(currentChar) && !escape;
         }
         return index;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
index 8491498..560a47c 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
@@ -310,7 +310,7 @@ public class CharBuf extends Writer implements CharSequence {
             capacity = buffer.length;
         }
 
-        arraycopy(chars, 0, buffer, location, chars.length);
+        System.arraycopy(chars, 0, buffer, location, chars.length);
         location += chars.length;
         return this;
     }
@@ -328,7 +328,7 @@ public class CharBuf extends Writer implements CharSequence {
         _buffer[_location] = '"';
         _location++;
 
-        arraycopy(chars, 0, _buffer, _location, chars.length);
+        System.arraycopy(chars, 0, _buffer, _location, chars.length);
 
         _location += (chars.length);
         _buffer[_location] = '"';
@@ -558,14 +558,6 @@ public class CharBuf extends Writer implements CharSequence {
         return this;
     }
 
-    private static void sysstemarraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
-        System.arraycopy(src, srcPos, dest, destPos, length);
-    }
-
-    private static void arraycopy(final char[] src, final int srcPos, final char[] dest, final int destPos, final int length) {
-        sysstemarraycopy(src, srcPos, dest, destPos, length);
-    }
-
     public CharBuf add(byte[] bytes, int start, int end) {
         int charsLength = end - start;
         if (charsLength + location > capacity) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
index 6ec6220..9d76cd6 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharSequenceValue.java
@@ -158,9 +158,8 @@ public class CharSequenceValue implements Value, CharSequence {
         if (startIndex != value1.startIndex) return false;
         if (!Arrays.equals(buffer, value1.buffer)) return false;
         if (type != value1.type) return false;
-        if (value != null ? !value.equals(value1.value) : value1.value != null) return false;
+        return value != null ? value.equals(value1.value) : value1.value == null;
 
-        return true;
     }
 
     public int hashCode() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
index 75c8a91..5a07c6b 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/Dates.java
@@ -33,8 +33,7 @@ public class Dates {
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(time);
         calendar.setTimeZone(UTC_TIME_ZONE);
-        long utcNow = calendar.getTime().getTime();
-        return utcNow;
+        return calendar.getTime().getTime();
     }
 
     private static Date internalDate(TimeZone tz, int year, int month, int day, int hour,
@@ -72,7 +71,7 @@ public class Dates {
     public static Date fromISO8601(char[] charArray, int from, int to) {
         try {
             if (isISO8601(charArray, from, to)) {
-                int year = CharScanner.parseIntFromTo(charArray, from + 0, from + 4);
+                int year = CharScanner.parseIntFromTo(charArray, from, from + 4);
                 int month = CharScanner.parseIntFromTo(charArray, from + 5, from + 7);
                 int day = CharScanner.parseIntFromTo(charArray, from + 8, from + 10);
                 int hour = CharScanner.parseIntFromTo(charArray, from + 11, from + 13);
@@ -85,10 +84,7 @@ public class Dates {
                 if (charArray[from + 19] == 'Z') {
                     tz = TimeZone.getTimeZone("GMT");
                 } else {
-                    StringBuilder builder = new StringBuilder(9);
-                    builder.append("GMT");
-                    builder.append(charArray, from + 19, 6);
-                    String tzStr = builder.toString();
+                    String tzStr = "GMT" + String.valueOf(charArray, from + 19, 6);
                     tz = TimeZone.getTimeZone(tzStr);
                 }
                 return toDate(tz, year, month, day, hour, minute, second);
@@ -103,7 +99,7 @@ public class Dates {
     public static Date fromJsonDate(char[] charArray, int from, int to) {
         try {
             if (isJsonDate(charArray, from, to)) {
-                int year = CharScanner.parseIntFromTo(charArray, from + 0, from + 4);
+                int year = CharScanner.parseIntFromTo(charArray, from, from + 4);
                 int month = CharScanner.parseIntFromTo(charArray, from + 5, from + 7);
                 int day = CharScanner.parseIntFromTo(charArray, from + 8, from + 10);
                 int hour = CharScanner.parseIntFromTo(charArray, from + 11, from + 13);
@@ -154,13 +150,9 @@ public class Dates {
         final int length = to - start;
 
         try {
-            if (length == JSON_TIME_LENGTH || length == LONG_ISO_8601_TIME_LENGTH
-                    || length == SHORT_ISO_8601_TIME_LENGTH || (length >= 17 && (charArray[start + 16] == ':'))
-                    ) {
-                return true;
-            }
+            return length == JSON_TIME_LENGTH || length == LONG_ISO_8601_TIME_LENGTH
+                    || length == SHORT_ISO_8601_TIME_LENGTH || (length >= 17 && (charArray[start + 16] == ':'));
 
-            return false;
         } catch (Exception ex) {
             ex.printStackTrace();
             return false;

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
index cc90a4d..a2dfb1e 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonFastParser.java
@@ -122,10 +122,10 @@ public class JsonFastParser extends JsonParserCharArray {
                 return decodeJsonObjectLazyFinalParse();
 
             case 't':
-                return decodeTrue() == true ? ValueContainer.TRUE : ValueContainer.FALSE;
+                return decodeTrue() ? ValueContainer.TRUE : ValueContainer.FALSE;
 
             case 'f':
-                return decodeFalse() == false ? ValueContainer.FALSE : ValueContainer.TRUE;
+                return !decodeFalse() ? ValueContainer.FALSE : ValueContainer.TRUE;
 
             case 'n':
                 return decodeNull() == null ? ValueContainer.NULL : ValueContainer.NULL;
@@ -219,9 +219,7 @@ public class JsonFastParser extends JsonParserCharArray {
 
         Type type = doubleFloat ? Type.DOUBLE : Type.INTEGER;
 
-        NumberValue value = new NumberValue(chop, type, startIndex, __index, this.charArray);
-
-        return value;
+        return new NumberValue(chop, type, startIndex, __index, this.charArray);
     }
 
     private Value decodeStringOverlay() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
index 6bb55b8..85120d1 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserCharArray.java
@@ -43,8 +43,7 @@ public class JsonParserCharArray extends BaseJsonParser {
         __index = 0;
         charArray = cs;
         lastIndex = cs.length - 1;
-        Object value = decodeValue();
-        return value;
+        return decodeValue();
     }
 
     protected final boolean hasMore() {
@@ -363,8 +362,7 @@ public class JsonParserCharArray extends BaseJsonParser {
             }
         } catch (Exception ex) {
             if (ex instanceof JsonException) {
-                JsonException jsonException = (JsonException) ex;
-                throw jsonException;
+                throw (JsonException) ex;
             }
             throw new JsonException(exceptionDetails("issue parsing JSON array"), ex);
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserLax.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserLax.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserLax.java
index 0238b35..09b87f2 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserLax.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/JsonParserLax.java
@@ -258,7 +258,7 @@ public class JsonParserLax extends JsonParserCharArray {
 
                 case 't':
                     if (isTrue()) {
-                        return decodeTrue() == true ? ValueContainer.TRUE : ValueContainer.FALSE;
+                        return decodeTrue() ? ValueContainer.TRUE : ValueContainer.FALSE;
                     } else {
                         value = decodeStringLax();
                     }
@@ -266,7 +266,7 @@ public class JsonParserLax extends JsonParserCharArray {
 
                 case 'f':
                     if (isFalse()) {
-                        return decodeFalse() == false ? ValueContainer.FALSE : ValueContainer.TRUE;
+                        return !decodeFalse() ? ValueContainer.FALSE : ValueContainer.TRUE;
                     } else {
                         value = decodeStringLax();
                     }
@@ -441,9 +441,7 @@ public class JsonParserLax extends JsonParserCharArray {
 
         Type type = doubleFloat ? Type.DOUBLE : Type.INTEGER;
 
-        NumberValue value = new NumberValue(chop, type, startIndex, __index, this.charArray);
-
-        return value;
+        return new NumberValue(chop, type, startIndex, __index, this.charArray);
     }
 
     private boolean isNull() {
@@ -530,11 +528,7 @@ public class JsonParserLax extends JsonParserCharArray {
                     }
 
                 case '\\':
-                    if (!escape) {
-                        escape = true;
-                    } else {
-                        escape = false;
-                    }
+                    escape = !escape;
                     encoded = true;
                     continue;
             }

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
index ceb9864..ffa5ffb 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/NumberValue.java
@@ -130,9 +130,8 @@ public class NumberValue extends java.lang.Number implements Value {
         if (startIndex != value1.startIndex) return false;
         if (!Arrays.equals(buffer, value1.buffer)) return false;
         if (type != value1.type) return false;
-        if (value != null ? !value.equals(value1.value) : value1.value != null) return false;
+        return value != null ? value.equals(value1.value) : value1.value == null;
 
-        return true;
     }
 
     public int hashCode() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/ReaderCharacterSource.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/ReaderCharacterSource.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/ReaderCharacterSource.java
index abff7d0..b2521c6 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/ReaderCharacterSource.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/ReaderCharacterSource.java
@@ -72,10 +72,8 @@ public class ReaderCharacterSource implements CharacterSource {
         try {
             if (index >= length && !done) {
                 readNextBuffer();
-            } else if (done && index >= length) {
-                more = false;
             } else {
-                more = true;
+                more = !(done && index >= length);
             }
         } catch (Exception ex) {
             String str = CharScanner.errorDetails("ensureBuffer issue", readBuf, index, ch);

http://git-wip-us.apache.org/repos/asf/groovy/blob/7d9af963/subprojects/groovy-json/src/main/java/groovy/json/internal/Value.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/Value.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/Value.java
index 77c9819..095609b 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/Value.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/Value.java
@@ -57,7 +57,7 @@ public interface Value {
 
     boolean isContainer(); //either a map or a collection
 
-    public void chop();
+    void chop();
 
     char charValue();
 }


[3/3] groovy git commit: refactor(json): inline to eliminate unused Classes (closes #318)

Posted by jw...@apache.org.
refactor(json): inline to eliminate unused Classes (closes #318)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2cdba2f0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2cdba2f0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2cdba2f0

Branch: refs/heads/master
Commit: 2cdba2f01e00fca51e2725cb97e98cc72559f23d
Parents: 7d9af96
Author: John Wagenleitner <jw...@apache.org>
Authored: Fri Apr 22 23:08:34 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sun Apr 24 09:05:00 2016 -0700

----------------------------------------------------------------------
 .../groovy/json/internal/BaseJsonParser.java    |  5 +++-
 .../src/main/java/groovy/json/internal/Byt.java | 30 -------------------
 .../main/java/groovy/json/internal/CharBuf.java |  3 +-
 .../java/groovy/json/internal/Charsets.java     | 31 --------------------
 4 files changed, 6 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2cdba2f0/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
index 03e94de..699b1b8 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/BaseJsonParser.java
@@ -24,6 +24,7 @@ import org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport;
 import org.codehaus.groovy.runtime.ResourceGroovyMethods;
 
 import java.io.*;
+import java.nio.charset.Charset;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -66,7 +67,9 @@ public abstract class BaseJsonParser implements JsonParser {
     protected static final boolean internKeys = Boolean.parseBoolean(System.getProperty("groovy.json.internKeys", "false"));
     protected static ConcurrentHashMap<String, String> internedKeysCache;
 
-    protected String charset = Charsets.UTF_8.name();
+    private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+    protected String charset = UTF_8.name();
 
     private CharBuf fileInputBuf;
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/2cdba2f0/subprojects/groovy-json/src/main/java/groovy/json/internal/Byt.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/Byt.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/Byt.java
deleted file mode 100644
index 289b6e5..0000000
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/Byt.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package groovy.json.internal;
-
-/**
- * @author Richard Hightower
- */
-public class Byt {
-
-    public static void charTo(byte[] b, char val) {
-        b[1] = (byte) (val);
-        b[0] = (byte) (val >>> 8);
-    }
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/2cdba2f0/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
index 560a47c..feaa614 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/internal/CharBuf.java
@@ -485,7 +485,8 @@ public class CharBuf extends Writer implements CharSequence {
                                 _location++;
                             }
                         } else {
-                            Byt.charTo(_charTo, c);
+                            _charTo[1] = (byte) (c);
+                            _charTo[0] = (byte) (c >>> 8);
 
                             for (int charByte : _charTo) {
                                 ByteScanner.encodeByteIntoTwoAsciiCharBytes(charByte, _encoded);

http://git-wip-us.apache.org/repos/asf/groovy/blob/2cdba2f0/subprojects/groovy-json/src/main/java/groovy/json/internal/Charsets.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/internal/Charsets.java b/subprojects/groovy-json/src/main/java/groovy/json/internal/Charsets.java
deleted file mode 100644
index f3bdbc2..0000000
--- a/subprojects/groovy-json/src/main/java/groovy/json/internal/Charsets.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package groovy.json.internal;
-
-import java.nio.charset.Charset;
-
-/**
- * @author Rick Hightower
- */
-public final class Charsets {
-
-    public static final Charset US_ASCII = Charset.forName("US-ASCII");
-    public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
-    public static final Charset UTF_8 = Charset.forName("UTF-8");
-}