From ab12e686045614d0a7baf70f4c40b45dceee3d10 Mon Sep 17 00:00:00 2001 From: soberich <25544967+soberich@users.noreply.github.com> Date: Sat, 2 Nov 2019 17:25:41 +0100 Subject: [PATCH] Rebase on upstream master, resolve errorprone. Shade left Google classes properly. Use diamond as Java 7 is minimal now. --- .../java/com/github/fge/jackson/JacksonUtils.java | 4 ++-- .../java/com/github/fge/jackson/JsonNumEquals.java | 6 +++--- src/main/java/com/github/fge/jackson/NodeType.java | 4 ++-- .../com}/google/common/base/Equivalence.java | 14 +++++++------- .../jackson/com}/google/common/base/Function.java | 4 ++-- .../google/common/base/FunctionalEquivalence.java | 2 +- .../google/common/base/PairwiseEquivalence.java | 2 +- .../jackson/com}/google/common/base/Predicate.java | 2 +- .../fge/jackson/jsonpointer/JsonPointer.java | 8 ++++---- .../fge/jackson/jsonpointer/TreePointer.java | 4 ++-- .../com/github/fge/jackson/JsonNodeReaderTest.java | 9 +++------ .../com/github/fge/jackson/JsonNumEqualsTest.java | 2 +- .../com/github/fge/jackson/SampleNodeProvider.java | 6 +++--- .../jackson/jsonpointer/JsonNodeResolverTest.java | 2 +- .../fge/jackson/jsonpointer/JsonPointerTest.java | 6 +++--- .../fge/jackson/jsonpointer/TreePointerTest.java | 4 ++-- 16 files changed, 38 insertions(+), 41 deletions(-) rename src/main/java/com/{ => github/fge/jackson/com}/google/common/base/Equivalence.java (97%) rename src/main/java/com/{ => github/fge/jackson/com}/google/common/base/Function.java (97%) rename src/main/java/com/{ => github/fge/jackson/com}/google/common/base/FunctionalEquivalence.java (97%) rename src/main/java/com/{ => github/fge/jackson/com}/google/common/base/PairwiseEquivalence.java (97%) rename src/main/java/com/{ => github/fge/jackson/com}/google/common/base/Predicate.java (97%) diff --git a/src/main/java/com/github/fge/jackson/JacksonUtils.java b/src/main/java/com/github/fge/jackson/JacksonUtils.java index 85c41ff..5750d77 100644 --- a/src/main/java/com/github/fge/jackson/JacksonUtils.java +++ b/src/main/java/com/github/fge/jackson/JacksonUtils.java @@ -99,7 +99,7 @@ public static Map asMap(final JsonNode node) return Collections.emptyMap(); final Iterator> iterator = node.fields(); - final Map ret = new HashMap(); + final Map ret = new HashMap<>(); Map.Entry entry; @@ -108,7 +108,7 @@ public static Map asMap(final JsonNode node) ret.put(entry.getKey(), entry.getValue()); } - return ret; + return Collections.unmodifiableMap(ret); } /** diff --git a/src/main/java/com/github/fge/jackson/JsonNumEquals.java b/src/main/java/com/github/fge/jackson/JsonNumEquals.java index b3b76c8..e061c8e 100644 --- a/src/main/java/com/github/fge/jackson/JsonNumEquals.java +++ b/src/main/java/com/github/fge/jackson/JsonNumEquals.java @@ -20,7 +20,7 @@ package com.github.fge.jackson; import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Equivalence; +import com.github.fge.jackson.com.google.common.base.Equivalence; import java.util.HashSet; import java.util.Iterator; @@ -183,7 +183,7 @@ private boolean objectEquals(final JsonNode a, final JsonNode b) /* * Grab the key set from the first node */ - final Set keys = new HashSet(); + final Set keys = new HashSet<>(); Iterator iterator1 = a.fieldNames(); while (iterator1.hasNext()) { final String next = iterator1.next(); @@ -198,7 +198,7 @@ private boolean objectEquals(final JsonNode a, final JsonNode b) * Grab the key set from the second node, and see if both sets are the * same. If not, objects are not equal, no need to check for children. */ - final Set set = new HashSet(); + final Set set = new HashSet<>(); Iterator iterator2 = b.fieldNames(); while (iterator2.hasNext()) { final String next = iterator2.next(); diff --git a/src/main/java/com/github/fge/jackson/NodeType.java b/src/main/java/com/github/fge/jackson/NodeType.java index ea15551..67ddf86 100644 --- a/src/main/java/com/github/fge/jackson/NodeType.java +++ b/src/main/java/com/github/fge/jackson/NodeType.java @@ -86,7 +86,7 @@ public enum NodeType * #getNodeType(JsonNode)}) */ private static final Map TOKEN_MAP - = new EnumMap(JsonToken.class); + = new EnumMap<>(JsonToken.class); static { TOKEN_MAP.put(JsonToken.START_ARRAY, ARRAY); @@ -99,7 +99,7 @@ public enum NodeType TOKEN_MAP.put(JsonToken.VALUE_STRING, STRING); final Map builder - = new HashMap(); + = new HashMap<>(); for (final NodeType type: NodeType.values()) builder.put(type.name, type); diff --git a/src/main/java/com/google/common/base/Equivalence.java b/src/main/java/com/github/fge/jackson/com/google/common/base/Equivalence.java similarity index 97% rename from src/main/java/com/google/common/base/Equivalence.java rename to src/main/java/com/github/fge/jackson/com/google/common/base/Equivalence.java index 5175b0f..11633dc 100644 --- a/src/main/java/com/google/common/base/Equivalence.java +++ b/src/main/java/com/github/fge/jackson/com/google/common/base/Equivalence.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.common.base; +package com.github.fge.jackson.com.google.common.base; import javax.annotation.Nullable; import java.io.Serializable; @@ -124,7 +124,7 @@ public final int hash(@Nullable T t) { * instance. */ public final Equivalence onResultOf(Function function) { - return new FunctionalEquivalence(function, this); + return new FunctionalEquivalence<>(function, this); } /** @@ -224,7 +224,7 @@ private Wrapper(Equivalence equivalence, @Nullable T reference) { public final Equivalence> pairwise() { // Ideally, the returned equivalence would support Iterable. However, // the need for this is so rare that it's not worth making callers deal with the ugly wildcard. - return new PairwiseEquivalence(this); + return new PairwiseEquivalence<>(this); } /** @@ -232,7 +232,7 @@ public final Equivalence> pairwise() { * equivalent to {@code target} according to this equivalence relation. */ public final Predicate equivalentTo(@Nullable T target) { - return new EquivalentToPredicate(this, target); + return new EquivalentToPredicate<>(this, target); } private static final class EquivalentToPredicate implements Predicate, Serializable { @@ -258,8 +258,8 @@ private static final class EquivalentToPredicate implements Predicate, Ser } if (obj instanceof EquivalentToPredicate) { EquivalentToPredicate that = (EquivalentToPredicate) obj; - return equivalence.equals(that.equivalence) - && target == that.target || (target != null && target.equals(that.target)); + return (equivalence.equals(that.equivalence) + && (target == that.target)) || ((target != null) && target.equals(that.target)); } return false; } @@ -330,4 +330,4 @@ private Object readResolve() { } private static final long serialVersionUID = 1; } -} \ No newline at end of file +} diff --git a/src/main/java/com/google/common/base/Function.java b/src/main/java/com/github/fge/jackson/com/google/common/base/Function.java similarity index 97% rename from src/main/java/com/google/common/base/Function.java rename to src/main/java/com/github/fge/jackson/com/google/common/base/Function.java index a375ade..fb53cd2 100644 --- a/src/main/java/com/google/common/base/Function.java +++ b/src/main/java/com/github/fge/jackson/com/google/common/base/Function.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.common.base; +package com.github.fge.jackson.com.google.common.base; import javax.annotation.Nullable; @@ -61,4 +61,4 @@ public interface Function { */ @Override boolean equals(@Nullable Object object); -} \ No newline at end of file +} diff --git a/src/main/java/com/google/common/base/FunctionalEquivalence.java b/src/main/java/com/github/fge/jackson/com/google/common/base/FunctionalEquivalence.java similarity index 97% rename from src/main/java/com/google/common/base/FunctionalEquivalence.java rename to src/main/java/com/github/fge/jackson/com/google/common/base/FunctionalEquivalence.java index 730168f..423a096 100644 --- a/src/main/java/com/google/common/base/FunctionalEquivalence.java +++ b/src/main/java/com/github/fge/jackson/com/google/common/base/FunctionalEquivalence.java @@ -14,7 +14,7 @@ * the License. */ -package com.google.common.base; +package com.github.fge.jackson.com.google.common.base; import javax.annotation.Nullable; import java.io.Serializable; diff --git a/src/main/java/com/google/common/base/PairwiseEquivalence.java b/src/main/java/com/github/fge/jackson/com/google/common/base/PairwiseEquivalence.java similarity index 97% rename from src/main/java/com/google/common/base/PairwiseEquivalence.java rename to src/main/java/com/github/fge/jackson/com/google/common/base/PairwiseEquivalence.java index 8466b76..d1d2f19 100644 --- a/src/main/java/com/google/common/base/PairwiseEquivalence.java +++ b/src/main/java/com/github/fge/jackson/com/google/common/base/PairwiseEquivalence.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.common.base; +package com.github.fge.jackson.com.google.common.base; import javax.annotation.Nullable; import java.io.Serializable; diff --git a/src/main/java/com/google/common/base/Predicate.java b/src/main/java/com/github/fge/jackson/com/google/common/base/Predicate.java similarity index 97% rename from src/main/java/com/google/common/base/Predicate.java rename to src/main/java/com/github/fge/jackson/com/google/common/base/Predicate.java index fe51465..6ffa6d0 100644 --- a/src/main/java/com/google/common/base/Predicate.java +++ b/src/main/java/com/github/fge/jackson/com/google/common/base/Predicate.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.common.base; +package com.github.fge.jackson.com.google.common.base; import javax.annotation.Nullable; diff --git a/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java b/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java index 670e50b..0aae6a5 100644 --- a/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java +++ b/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java @@ -72,7 +72,7 @@ public static JsonPointer empty() */ public static JsonPointer of(final Object first, final Object... other) { - final List tokens = new ArrayList(); + final List tokens = new ArrayList<>(); tokens.add(ReferenceToken.fromRaw(first.toString())); @@ -120,7 +120,7 @@ public JsonPointer append(final String raw) final ReferenceToken refToken = ReferenceToken.fromRaw(raw); final JsonNodeResolver resolver = new JsonNodeResolver(refToken); final List> list - = new ArrayList>(); + = new ArrayList<>(); for (final TokenResolver tokenResolver : tokenResolvers) { if (tokenResolver != null) { list.add(tokenResolver); @@ -154,7 +154,7 @@ public JsonPointer append(final JsonPointer other) { BUNDLE.checkNotNull(other, "nullInput"); final List> list - = new ArrayList>(); + = new ArrayList<>(); for (final TokenResolver tokenResolver : tokenResolvers) { if (tokenResolver != null) { list.add(tokenResolver); @@ -191,7 +191,7 @@ public JsonPointer parent() private static List> fromTokens( final List tokens) { - final List> list = new ArrayList>(); + final List> list = new ArrayList<>(); for (final ReferenceToken token: tokens) list.add(new JsonNodeResolver(token)); return list; diff --git a/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java b/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java index df82ef8..937fc70 100644 --- a/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java +++ b/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java @@ -92,7 +92,7 @@ protected TreePointer(final T missing, final List> tokenResolvers) { this.missing = missing; - this.tokenResolvers = Collections.unmodifiableList(new ArrayList>(tokenResolvers)); + this.tokenResolvers = Collections.unmodifiableList(new ArrayList<>(tokenResolvers)); } /** @@ -206,7 +206,7 @@ protected static List tokensFromInput(final String input) throws JsonPointerException { String s = BUNDLE.checkNotNull(input, "nullInput"); - final List ret = new ArrayList(); + final List ret = new ArrayList<>(); String cooked; int index; char c; diff --git a/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java b/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java index 7a60cd4..2965822 100644 --- a/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java +++ b/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java @@ -33,6 +33,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -70,7 +71,7 @@ public void readerIsClosedOnRead() @DataProvider public Iterator getMalformedData() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); list.add(new Object[] { "", "read.noContent"}); list.add(new Object[] { "[]{}", "read.trailingData"}); @@ -104,11 +105,7 @@ private static Supplier provideInputStream(final String input) @Override public InputStream get() { - try { - return new ByteArrayInputStream(input.getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("Unhandled exception", e); - } + return new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); } }; } diff --git a/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java b/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java index cecb942..af4d068 100644 --- a/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java +++ b/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java @@ -49,7 +49,7 @@ public void initData() @DataProvider public Iterator getInputs() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); JsonNode reference; diff --git a/src/test/java/com/github/fge/jackson/SampleNodeProvider.java b/src/test/java/com/github/fge/jackson/SampleNodeProvider.java index 4f997fb..23817f7 100644 --- a/src/test/java/com/github/fge/jackson/SampleNodeProvider.java +++ b/src/test/java/com/github/fge/jackson/SampleNodeProvider.java @@ -35,7 +35,7 @@ private SampleNodeProvider() } static { - SAMPLE_DATA = new EnumMap(NodeType.class); + SAMPLE_DATA = new EnumMap<>(NodeType.class); SAMPLE_DATA.put(NodeType.ARRAY, FACTORY.arrayNode()); SAMPLE_DATA.put(NodeType.BOOLEAN, FACTORY.booleanNode(true)); @@ -52,10 +52,10 @@ private SampleNodeProvider() // differ... public static Iterator getSamples(final EnumSet types) { - final Map map = new EnumMap(SAMPLE_DATA); + final Map map = new EnumMap<>(SAMPLE_DATA); map.keySet().retainAll(types); - final List samples = new ArrayList(); + final List samples = new ArrayList<>(); for (final JsonNode input : map.values()) { samples.add(new Object[] { input }); } diff --git a/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java b/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java index d4a042f..6f22fda 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java @@ -104,7 +104,7 @@ public void resolvingArrayIndicesWorks() @DataProvider public Iterator invalidIndices() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); list.add(new Object[] { "-1" }); list.add(new Object[] { "232398087298731987987232" }); diff --git a/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java b/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java index c04fded..be19a61 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java @@ -66,7 +66,7 @@ public void cannotAppendNullPointer() @DataProvider public Iterator rawPointers() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); final JsonNode testNode = testData.get("pointers"); final Map map = JacksonUtils.asMap(testNode); @@ -89,7 +89,7 @@ public void rawPointerResolvingWorks(final String input, @DataProvider public Iterator uriPointers() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); final JsonNode testNode = testData.get("uris"); final Map map = JacksonUtils.asMap(testNode); @@ -181,7 +181,7 @@ public void staticConstructionFromTokensWorks() @DataProvider public Iterator parentTestData() { - final List list = new ArrayList(); + final List list = new ArrayList<>(); // Empty list.add(new Object[] { JsonPointer.empty(), JsonPointer.empty() }); diff --git a/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java b/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java index a42a406..2edc050 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java @@ -154,7 +154,7 @@ public void gettingPathOfMissingNodeReturnsMissingNode() @Test public void treePointerCanTellWhetherItIsEmpty() { - final List> list = new ArrayList>(); + final List> list = new ArrayList<>(); assertTrue(new DummyPointer(null, list).isEmpty()); @@ -168,7 +168,7 @@ public void treePointerCanTellWhetherItIsEmpty() @Test public void treeIsUnalteredWhenOriginalListIsAltered() { - final List> list = new ArrayList>(); + final List> list = new ArrayList<>(); final DummyPointer dummy = new DummyPointer(null, list); @SuppressWarnings("unchecked")