From df01e943e524c1b569930b8b4cf50c873513698c Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Tue, 3 Oct 2023 18:56:07 +0200 Subject: [PATCH] Improve formatting (#2505) * Improve formatting * Move `&&` to start of line --- .../src/main/java/com/google/gson/GsonBuilder.java | 8 ++++---- .../java/com/google/gson/stream/JsonReader.java | 4 ++-- .../BagOfPrimitivesDeserializationBenchmark.java | 4 ++-- .../CollectionsDeserializationBenchmark.java | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index 8a3f273eb0..15e14cb7b6 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -675,7 +675,7 @@ public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { || typeAdapter instanceof InstanceCreator || typeAdapter instanceof TypeAdapter); - if (isTypeObjectOrJsonElement(type)){ + if (isTypeObjectOrJsonElement(type)) { throw new IllegalArgumentException("Cannot override built-in adapter for " + type); } @@ -695,9 +695,9 @@ public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { } private boolean isTypeObjectOrJsonElement(Type type) { - return type instanceof Class && - (type == Object.class - || JsonElement.class.isAssignableFrom((Class) type)); + return type instanceof Class + && (type == Object.class + || JsonElement.class.isAssignableFrom((Class) type)); } /** diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index b85fba8f7c..534e7a4f10 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -804,7 +804,7 @@ private int peekNumber() throws IOException { // We've read a complete number. Decide if it's a PEEKED_LONG or a PEEKED_NUMBER. // Don't store -0 as long; user might want to read it as double -0.0 // Don't try to convert Long.MIN_VALUE to positive long; it would overflow MAX_VALUE - if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative) && (value!=0 || !negative)) { + if (last == NUMBER_CHAR_DIGIT && fitsInLong && (value != Long.MIN_VALUE || negative) && (value != 0 || !negative)) { peekedLong = negative ? value : -value; pos += i; return peeked = PEEKED_LONG; @@ -1755,7 +1755,7 @@ private void consumeNonExecutePrefix() throws IOException { int p = pos; char[] buf = buffer; - if(buf[p] != ')' || buf[p + 1] != ']' || buf[p + 2] != '}' || buf[p + 3] != '\'' || buf[p + 4] != '\n') { + if (buf[p] != ')' || buf[p + 1] != ']' || buf[p + 2] != '}' || buf[p + 3] != '\'' || buf[p + 4] != '\n') { return; // not a security token! } diff --git a/metrics/src/main/java/com/google/gson/metrics/BagOfPrimitivesDeserializationBenchmark.java b/metrics/src/main/java/com/google/gson/metrics/BagOfPrimitivesDeserializationBenchmark.java index 80881dc8e6..2c74b39dc2 100644 --- a/metrics/src/main/java/com/google/gson/metrics/BagOfPrimitivesDeserializationBenchmark.java +++ b/metrics/src/main/java/com/google/gson/metrics/BagOfPrimitivesDeserializationBenchmark.java @@ -66,7 +66,7 @@ public void timeBagOfPrimitivesStreaming(int reps) throws IOException { int intValue = 0; boolean booleanValue = false; String stringValue = null; - while(jr.hasNext()) { + while (jr.hasNext()) { String name = jr.nextName(); if (name.equals("longValue")) { longValue = jr.nextLong(); @@ -96,7 +96,7 @@ public void timeBagOfPrimitivesReflectionStreaming(int reps) throws Exception { JsonReader jr = new JsonReader(reader); jr.beginObject(); BagOfPrimitives bag = new BagOfPrimitives(); - while(jr.hasNext()) { + while (jr.hasNext()) { String name = jr.nextName(); for (Field field : BagOfPrimitives.class.getDeclaredFields()) { if (field.getName().equals(name)) { diff --git a/metrics/src/main/java/com/google/gson/metrics/CollectionsDeserializationBenchmark.java b/metrics/src/main/java/com/google/gson/metrics/CollectionsDeserializationBenchmark.java index c10202db8d..49868c1516 100644 --- a/metrics/src/main/java/com/google/gson/metrics/CollectionsDeserializationBenchmark.java +++ b/metrics/src/main/java/com/google/gson/metrics/CollectionsDeserializationBenchmark.java @@ -56,7 +56,7 @@ void setUp() throws Exception { * Benchmark to measure Gson performance for deserializing an object */ public void timeCollectionsDefault(int reps) { - for (int i=0; i bags = new ArrayList<>(); - while(jr.hasNext()) { + while (jr.hasNext()) { jr.beginObject(); long longValue = 0; int intValue = 0; boolean booleanValue = false; String stringValue = null; - while(jr.hasNext()) { + while (jr.hasNext()) { String name = jr.nextName(); if (name.equals("longValue")) { longValue = jr.nextLong(); @@ -105,15 +105,15 @@ public void timeCollectionsStreaming(int reps) throws IOException { */ @SuppressWarnings("ModifiedButNotUsed") public void timeCollectionsReflectionStreaming(int reps) throws Exception { - for (int i=0; i bags = new ArrayList<>(); - while(jr.hasNext()) { + while (jr.hasNext()) { jr.beginObject(); BagOfPrimitives bag = new BagOfPrimitives(); - while(jr.hasNext()) { + while (jr.hasNext()) { String name = jr.nextName(); for (Field field : BagOfPrimitives.class.getDeclaredFields()) { if (field.getName().equals(name)) {