Skip to content

Commit f5e2e16

Browse files
committed
Format the code following Google Java Style Guide
1 parent cea692d commit f5e2e16

File tree

108 files changed

+2087
-2223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2087
-2223
lines changed

examples/android-proguard-example/src/com/google/gson/examples/android/model/Cart.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,34 @@ public Cart(List<LineItem> lineItems, String buyerName, String creditCard) {
4141
this.creditCard = creditCard;
4242
}
4343

44+
@SuppressWarnings("unchecked")
45+
public static String getSimpleTypeName(Type type) {
46+
if (type == null) {
47+
return "null";
48+
}
49+
if (type instanceof Class) {
50+
return ((Class)type).getSimpleName();
51+
} else if (type instanceof ParameterizedType) {
52+
ParameterizedType pType = (ParameterizedType) type;
53+
StringBuilder sb = new StringBuilder(getSimpleTypeName(pType.getRawType()));
54+
sb.append('<');
55+
boolean first = true;
56+
for (Type argumentType : pType.getActualTypeArguments()) {
57+
if (first) {
58+
first = false;
59+
} else {
60+
sb.append(',');
61+
}
62+
sb.append(getSimpleTypeName(argumentType));
63+
}
64+
sb.append('>');
65+
return sb.toString();
66+
} else if (type instanceof WildcardType) {
67+
return "?";
68+
}
69+
return type.toString();
70+
}
71+
4472
public List<LineItem> getLineItems() {
4573
return lineItems;
4674
}
@@ -77,32 +105,4 @@ public String toString() {
77105
+ "LINE_ITEMS: " + itemsText.toString() + "]";
78106
}
79107

80-
@SuppressWarnings("unchecked")
81-
public static String getSimpleTypeName(Type type) {
82-
if (type == null) {
83-
return "null";
84-
}
85-
if (type instanceof Class) {
86-
return ((Class)type).getSimpleName();
87-
} else if (type instanceof ParameterizedType) {
88-
ParameterizedType pType = (ParameterizedType) type;
89-
StringBuilder sb = new StringBuilder(getSimpleTypeName(pType.getRawType()));
90-
sb.append('<');
91-
boolean first = true;
92-
for (Type argumentType : pType.getActualTypeArguments()) {
93-
if (first) {
94-
first = false;
95-
} else {
96-
sb.append(',');
97-
}
98-
sb.append(getSimpleTypeName(argumentType));
99-
}
100-
sb.append('>');
101-
return sb.toString();
102-
} else if (type instanceof WildcardType) {
103-
return "?";
104-
}
105-
return type.toString();
106-
}
107-
108108
}

extras/src/main/java/com/google/gson/extras/examples/rawcollections/RawCollectionsExample.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,13 @@
1515
*/
1616
package com.google.gson.extras.examples.rawcollections;
1717

18-
import java.util.ArrayList;
19-
import java.util.Collection;
20-
2118
import com.google.gson.Gson;
2219
import com.google.gson.JsonArray;
2320
import com.google.gson.JsonParser;
21+
import java.util.ArrayList;
22+
import java.util.Collection;
2423

2524
public class RawCollectionsExample {
26-
static class Event {
27-
private String name;
28-
private String source;
29-
private Event(String name, String source) {
30-
this.name = name;
31-
this.source = source;
32-
}
33-
@Override
34-
public String toString() {
35-
return String.format("(name=%s, source=%s)", name, source);
36-
}
37-
}
38-
3925
@SuppressWarnings({ "unchecked", "rawtypes" })
4026
public static void main(String[] args) {
4127
Gson gson = new Gson();
@@ -51,4 +37,17 @@ public static void main(String[] args) {
5137
Event event = gson.fromJson(array.get(2), Event.class);
5238
System.out.printf("Using Gson.fromJson() to get: %s, %d, %s", message, number, event);
5339
}
40+
41+
static class Event {
42+
private String name;
43+
private String source;
44+
private Event(String name, String source) {
45+
this.name = name;
46+
this.source = source;
47+
}
48+
@Override
49+
public String toString() {
50+
return String.format("(name=%s, source=%s)", name, source);
51+
}
52+
}
5453
}

extras/src/main/java/com/google/gson/graph/GraphAdapterBuilder.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,23 +269,20 @@ static class Element<T> {
269269
* This element's name in the top level graph object.
270270
*/
271271
private final String id;
272-
272+
/**
273+
* The element to deserialize. Unused in serialization.
274+
*/
275+
private final JsonElement element;
273276
/**
274277
* The value if known. During deserialization this is lazily populated.
275278
*/
276279
private T value;
277-
278280
/**
279281
* This element's type adapter if known. During deserialization this is
280282
* lazily populated.
281283
*/
282284
private TypeAdapter<T> typeAdapter;
283285

284-
/**
285-
* The element to deserialize. Unused in serialization.
286-
*/
287-
private final JsonElement element;
288-
289286
Element(T value, String id, TypeAdapter<T> typeAdapter, JsonElement element) {
290287
this.value = value;
291288
this.id = id;

extras/src/main/java/com/google/gson/typeadapters/PostConstructAdapterFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616

1717
package com.google.gson.typeadapters;
1818

19-
import java.io.IOException;
20-
import java.lang.reflect.InvocationTargetException;
21-
import java.lang.reflect.Method;
22-
23-
import javax.annotation.PostConstruct;
24-
2519
import com.google.gson.Gson;
2620
import com.google.gson.TypeAdapter;
2721
import com.google.gson.TypeAdapterFactory;
2822
import com.google.gson.reflect.TypeToken;
2923
import com.google.gson.stream.JsonReader;
3024
import com.google.gson.stream.JsonWriter;
25+
import java.io.IOException;
26+
import java.lang.reflect.InvocationTargetException;
27+
import java.lang.reflect.Method;
28+
import javax.annotation.PostConstruct;
3129

3230
public class PostConstructAdapterFactory implements TypeAdapterFactory {
3331
// copied from https://gist.github.com/swankjesse/20df26adaf639ed7fd160f145a0b661a

extras/src/main/java/com/google/gson/typeadapters/UtcDateTypeAdapter.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package com.google.gson.typeadapters;
1818

19+
import com.google.gson.JsonParseException;
20+
import com.google.gson.TypeAdapter;
21+
import com.google.gson.stream.JsonReader;
22+
import com.google.gson.stream.JsonWriter;
1923
import java.io.IOException;
2024
import java.text.ParseException;
2125
import java.text.ParsePosition;
@@ -24,46 +28,12 @@
2428
import java.util.GregorianCalendar;
2529
import java.util.Locale;
2630
import java.util.TimeZone;
27-
import com.google.gson.JsonParseException;
28-
import com.google.gson.TypeAdapter;
29-
import com.google.gson.stream.JsonReader;
30-
import com.google.gson.stream.JsonToken;
31-
import com.google.gson.stream.JsonWriter;
3231

3332
public final class UtcDateTypeAdapter extends TypeAdapter<Date> {
34-
private final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
35-
36-
@Override
37-
public void write(JsonWriter out, Date date) throws IOException {
38-
if (date == null) {
39-
out.nullValue();
40-
} else {
41-
String value = format(date, true, UTC_TIME_ZONE);
42-
out.value(value);
43-
}
44-
}
45-
46-
@Override
47-
public Date read(JsonReader in) throws IOException {
48-
try {
49-
switch (in.peek()) {
50-
case NULL:
51-
in.nextNull();
52-
return null;
53-
default:
54-
String date = in.nextString();
55-
// Instead of using iso8601Format.parse(value), we use Jackson's date parsing
56-
// This is because Android doesn't support XXX because it is JDK 1.6
57-
return parse(date, new ParsePosition(0));
58-
}
59-
} catch (ParseException e) {
60-
throw new JsonParseException(e);
61-
}
62-
}
63-
6433
// Date parsing code from Jackson databind ISO8601Utils.java
6534
// https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/util/ISO8601Utils.java
6635
private static final String GMT_ID = "GMT";
36+
private final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
6737

6838
/**
6939
* Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
@@ -113,6 +83,7 @@ private static String format(Date date, boolean millis, TimeZone tz) {
11383

11484
return formatted.toString();
11585
}
86+
11687
/**
11788
* Zero pad a number to a specified length
11889
*
@@ -279,4 +250,32 @@ private static int parseInt(String value, int beginIndex, int endIndex) throws N
279250
}
280251
return -result;
281252
}
253+
254+
@Override
255+
public void write(JsonWriter out, Date date) throws IOException {
256+
if (date == null) {
257+
out.nullValue();
258+
} else {
259+
String value = format(date, true, UTC_TIME_ZONE);
260+
out.value(value);
261+
}
262+
}
263+
264+
@Override
265+
public Date read(JsonReader in) throws IOException {
266+
try {
267+
switch (in.peek()) {
268+
case NULL:
269+
in.nextNull();
270+
return null;
271+
default:
272+
String date = in.nextString();
273+
// Instead of using iso8601Format.parse(value), we use Jackson's date parsing
274+
// This is because Android doesn't support XXX because it is JDK 1.6
275+
return parse(date, new ParsePosition(0));
276+
}
277+
} catch (ParseException e) {
278+
throw new JsonParseException(e);
279+
}
280+
}
282281
}

extras/src/test/java/com/google/gson/graph/GraphAdapterBuilderTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertSame;
2121

22+
import com.google.gson.Gson;
23+
import com.google.gson.GsonBuilder;
24+
import com.google.gson.reflect.TypeToken;
2225
import java.lang.reflect.Type;
2326
import java.util.ArrayList;
2427
import java.util.Collections;
2528
import java.util.List;
26-
2729
import org.junit.Test;
2830

29-
import com.google.gson.Gson;
30-
import com.google.gson.GsonBuilder;
31-
import com.google.gson.reflect.TypeToken;
32-
3331
public final class GraphAdapterBuilderTest {
3432
@Test
3533
public void testSerialization() {

0 commit comments

Comments
 (0)