Skip to content

Commit

Permalink
Rebase on upstream master, resolve errorprone. Shade left Google clas…
Browse files Browse the repository at this point in the history
…ses properly. Use diamond as Java 7 is minimal now.
  • Loading branch information
soberich committed Nov 2, 2019
1 parent 7e26865 commit ab12e68
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/fge/jackson/JacksonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static Map<String, JsonNode> asMap(final JsonNode node)
return Collections.emptyMap();

final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
final Map<String, JsonNode> ret = new HashMap<String, JsonNode>();
final Map<String, JsonNode> ret = new HashMap<>();

Map.Entry<String, JsonNode> entry;

Expand All @@ -108,7 +108,7 @@ public static Map<String, JsonNode> asMap(final JsonNode node)
ret.put(entry.getKey(), entry.getValue());
}

return ret;
return Collections.unmodifiableMap(ret);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/fge/jackson/JsonNumEquals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +183,7 @@ private boolean objectEquals(final JsonNode a, final JsonNode b)
/*
* Grab the key set from the first node
*/
final Set<String> keys = new HashSet<String>();
final Set<String> keys = new HashSet<>();
Iterator<String> iterator1 = a.fieldNames();
while (iterator1.hasNext()) {
final String next = iterator1.next();
Expand All @@ -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<String> set = new HashSet<String>();
final Set<String> set = new HashSet<>();
Iterator<String> iterator2 = b.fieldNames();
while (iterator2.hasNext()) {
final String next = iterator2.next();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/fge/jackson/NodeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public enum NodeType
* #getNodeType(JsonNode)})
*/
private static final Map<JsonToken, NodeType> TOKEN_MAP
= new EnumMap<JsonToken, NodeType>(JsonToken.class);
= new EnumMap<>(JsonToken.class);

static {
TOKEN_MAP.put(JsonToken.START_ARRAY, ARRAY);
Expand All @@ -99,7 +99,7 @@ public enum NodeType
TOKEN_MAP.put(JsonToken.VALUE_STRING, STRING);

final Map<String, NodeType> builder
= new HashMap<String, NodeType>();
= new HashMap<>();

for (final NodeType type: NodeType.values())
builder.put(type.name, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +124,7 @@ public final int hash(@Nullable T t) {
* instance.
*/
public final <F> Equivalence<F> onResultOf(Function<F, ? extends T> function) {
return new FunctionalEquivalence<F, T>(function, this);
return new FunctionalEquivalence<>(function, this);
}

/**
Expand Down Expand Up @@ -224,15 +224,15 @@ private Wrapper(Equivalence<? super T> equivalence, @Nullable T reference) {
public final <S extends T> Equivalence<Iterable<S>> pairwise() {
// Ideally, the returned equivalence would support Iterable<? extends T>. However,
// the need for this is so rare that it's not worth making callers deal with the ugly wildcard.
return new PairwiseEquivalence<S>(this);
return new PairwiseEquivalence<>(this);
}

/**
* Returns a predicate that evaluates to true if and only if the input is
* equivalent to {@code target} according to this equivalence relation.
*/
public final Predicate<T> equivalentTo(@Nullable T target) {
return new EquivalentToPredicate<T>(this, target);
return new EquivalentToPredicate<>(this, target);
}

private static final class EquivalentToPredicate<T> implements Predicate<T>, Serializable {
Expand All @@ -258,8 +258,8 @@ private static final class EquivalentToPredicate<T> implements Predicate<T>, 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;
}
Expand Down Expand Up @@ -330,4 +330,4 @@ private Object readResolve() {
}
private static final long serialVersionUID = 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,4 +61,4 @@ public interface Function<F, T> {
*/
@Override
boolean equals(@Nullable Object object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static JsonPointer empty()
*/
public static JsonPointer of(final Object first, final Object... other)
{
final List<ReferenceToken> tokens = new ArrayList<ReferenceToken>();
final List<ReferenceToken> tokens = new ArrayList<>();

tokens.add(ReferenceToken.fromRaw(first.toString()));

Expand Down Expand Up @@ -120,7 +120,7 @@ public JsonPointer append(final String raw)
final ReferenceToken refToken = ReferenceToken.fromRaw(raw);
final JsonNodeResolver resolver = new JsonNodeResolver(refToken);
final List<TokenResolver<JsonNode>> list
= new ArrayList<TokenResolver<JsonNode>>();
= new ArrayList<>();
for (final TokenResolver<JsonNode> tokenResolver : tokenResolvers) {
if (tokenResolver != null) {
list.add(tokenResolver);
Expand Down Expand Up @@ -154,7 +154,7 @@ public JsonPointer append(final JsonPointer other)
{
BUNDLE.checkNotNull(other, "nullInput");
final List<TokenResolver<JsonNode>> list
= new ArrayList<TokenResolver<JsonNode>>();
= new ArrayList<>();
for (final TokenResolver<JsonNode> tokenResolver : tokenResolvers) {
if (tokenResolver != null) {
list.add(tokenResolver);
Expand Down Expand Up @@ -191,7 +191,7 @@ public JsonPointer parent()
private static List<TokenResolver<JsonNode>> fromTokens(
final List<ReferenceToken> tokens)
{
final List<TokenResolver<JsonNode>> list = new ArrayList<TokenResolver<JsonNode>>();
final List<TokenResolver<JsonNode>> list = new ArrayList<>();
for (final ReferenceToken token: tokens)
list.add(new JsonNodeResolver(token));
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected TreePointer(final T missing,
final List<TokenResolver<T>> tokenResolvers)
{
this.missing = missing;
this.tokenResolvers = Collections.unmodifiableList(new ArrayList<TokenResolver<T>>(tokenResolvers));
this.tokenResolvers = Collections.unmodifiableList(new ArrayList<>(tokenResolvers));
}

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ protected static List<ReferenceToken> tokensFromInput(final String input)
throws JsonPointerException
{
String s = BUNDLE.checkNotNull(input, "nullInput");
final List<ReferenceToken> ret = new ArrayList<ReferenceToken>();
final List<ReferenceToken> ret = new ArrayList<>();
String cooked;
int index;
char c;
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void readerIsClosedOnRead()
@DataProvider
public Iterator<Object[]> getMalformedData()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();

list.add(new Object[] { "", "read.noContent"});
list.add(new Object[] { "[]{}", "read.trailingData"});
Expand Down Expand Up @@ -104,11 +105,7 @@ private static Supplier<InputStream> 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));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void initData()
@DataProvider
public Iterator<Object[]> getInputs()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();

JsonNode reference;

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/github/fge/jackson/SampleNodeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private SampleNodeProvider()
}

static {
SAMPLE_DATA = new EnumMap<NodeType, JsonNode>(NodeType.class);
SAMPLE_DATA = new EnumMap<>(NodeType.class);

SAMPLE_DATA.put(NodeType.ARRAY, FACTORY.arrayNode());
SAMPLE_DATA.put(NodeType.BOOLEAN, FACTORY.booleanNode(true));
Expand All @@ -52,10 +52,10 @@ private SampleNodeProvider()
// differ...
public static Iterator<Object[]> getSamples(final EnumSet<NodeType> types)
{
final Map<NodeType, JsonNode> map = new EnumMap<NodeType, JsonNode>(SAMPLE_DATA);
final Map<NodeType, JsonNode> map = new EnumMap<>(SAMPLE_DATA);
map.keySet().retainAll(types);

final List<Object[]> samples = new ArrayList<Object[]>();
final List<Object[]> samples = new ArrayList<>();
for (final JsonNode input : map.values()) {
samples.add(new Object[] { input });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void resolvingArrayIndicesWorks()
@DataProvider
public Iterator<Object[]> invalidIndices()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();

list.add(new Object[] { "-1" });
list.add(new Object[] { "232398087298731987987232" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void cannotAppendNullPointer()
@DataProvider
public Iterator<Object[]> rawPointers()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();
final JsonNode testNode = testData.get("pointers");
final Map<String, JsonNode> map = JacksonUtils.asMap(testNode);

Expand All @@ -89,7 +89,7 @@ public void rawPointerResolvingWorks(final String input,
@DataProvider
public Iterator<Object[]> uriPointers()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();
final JsonNode testNode = testData.get("uris");
final Map<String, JsonNode> map = JacksonUtils.asMap(testNode);

Expand Down Expand Up @@ -181,7 +181,7 @@ public void staticConstructionFromTokensWorks()
@DataProvider
public Iterator<Object[]> parentTestData()
{
final List<Object[]> list = new ArrayList<Object[]>();
final List<Object[]> list = new ArrayList<>();

// Empty
list.add(new Object[] { JsonPointer.empty(), JsonPointer.empty() });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void gettingPathOfMissingNodeReturnsMissingNode()
@Test
public void treePointerCanTellWhetherItIsEmpty()
{
final List<TokenResolver<TreeNode>> list = new ArrayList<TokenResolver<TreeNode>>();
final List<TokenResolver<TreeNode>> list = new ArrayList<>();

assertTrue(new DummyPointer(null, list).isEmpty());

Expand All @@ -168,7 +168,7 @@ public void treePointerCanTellWhetherItIsEmpty()
@Test
public void treeIsUnalteredWhenOriginalListIsAltered()
{
final List<TokenResolver<TreeNode>> list = new ArrayList<TokenResolver<TreeNode>>();
final List<TokenResolver<TreeNode>> list = new ArrayList<>();
final DummyPointer dummy = new DummyPointer(null, list);

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit ab12e68

Please sign in to comment.