Skip to content

Commit

Permalink
Shaded classes from Guava to keep the API stable
Browse files Browse the repository at this point in the history
  • Loading branch information
soberich committed Nov 2, 2019
1 parent a381e35 commit b857462
Show file tree
Hide file tree
Showing 17 changed files with 649 additions and 90 deletions.
4 changes: 2 additions & 2 deletions project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ targetCompatibility = JavaVersion.VERSION_1_7; // defaults to sourceCompatibilit
dependencies {
implementation(group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.9.9");
implementation(group: "com.github.fge", name: "msg-simple", version: "1.1");
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1");
testImplementation(group: "org.testng", name: "testng", version: "6.8.7") {
implementation(group: "com.google.code.findbugs", name: "jsr305", version: "3.0.2");
testImplementation(group: "org.testng", name: "testng", version: "7.0.0-beta1") {
exclude(group: "junit", module: "junit");
exclude(group: "org.beanshell", module: "bsh");
exclude(group: "org.yaml", module: "snakeyaml");
Expand Down
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
69 changes: 8 additions & 61 deletions src/main/java/com/github/fge/jackson/JsonNumEquals.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package com.github.fge.jackson;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.com.google.common.base.Equivalence;

import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
Expand All @@ -41,50 +41,21 @@
* kind of equality.</p>
*/
public final class JsonNumEquals
extends Equivalence<JsonNode>
{
private static final JsonNumEquals INSTANCE
private static final Equivalence<JsonNode> INSTANCE
= new JsonNumEquals();

private JsonNumEquals()
{
}

public static JsonNumEquals getInstance()
public static Equivalence<JsonNode> getInstance()
{
return INSTANCE;
}

/**
* Returns {@code true} if the given objects are considered equivalent.
*
* <p>The {@code equivalent} method implements an equivalence relation on object references:
*
* <ul>
* <li>It is <i>reflexive</i>: for any reference {@code x}, including null, {@code
* equivalent(x, x)} returns {@code true}.
* <li>It is <i>symmetric</i>: for any references {@code x} and {@code y}, {@code
* equivalent(x, y) == equivalent(y, x)}.
* <li>It is <i>transitive</i>: for any references {@code x}, {@code y}, and {@code z}, if
* {@code equivalent(x, y)} returns {@code true} and {@code equivalent(y, z)} returns {@code
* true}, then {@code equivalent(x, z)} returns {@code true}.
* <li>It is <i>consistent</i>: for any references {@code x} and {@code y}, multiple invocations
* of {@code equivalent(x, y)} consistently return {@code true} or consistently return {@code
* false} (provided that neither {@code x} nor {@code y} is modified).
* </ul>
* @param a x
* @param b y
* @return whether nodes are equal according to IETF RFCs
*/
public final boolean equivalent(@Nullable JsonNode a, @Nullable JsonNode b) {
if (a == b) {
return true;
}
if (a == null || b == null) {
return false;
}
return doEquivalent(a, b);
}

@Override
protected boolean doEquivalent(final JsonNode a, final JsonNode b)
{
/*
Expand Down Expand Up @@ -122,31 +93,7 @@ protected boolean doEquivalent(final JsonNode a, final JsonNode b)
return typeA == NodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b);
}

/**
* Returns a hash code for {@code t}.
*
* <p>The {@code hash} has the following properties:
* <ul>
* <li>It is <i>consistent</i>: for any reference {@code x}, multiple invocations of
* {@code hash(x}} consistently return the same value provided {@code x} remains unchanged
* according to the definition of the equivalence. The hash need not remain consistent from
* one execution of an application to another execution of the same application.
* <li>It is <i>distributable across equivalence</i>: for any references {@code x} and {@code y},
* if {@code equivalent(x, y)}, then {@code hash(x) == hash(y)}. It is <i>not</i> necessary
* that the hash be distributable across <i>inequivalence</i>. If {@code equivalence(x, y)}
* is false, {@code hash(x) == hash(y)} may still be true.
* <li>{@code hash(null)} is {@code 0}.
* </ul>
* @param t node to hash
* @return hash
*/
public final int hash(@Nullable JsonNode t) {
if (t == null) {
return 0;
}
return doHash(t);
}

@Override
protected int doHash(final JsonNode t)
{
/*
Expand Down Expand Up @@ -236,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 @@ -251,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
Loading

0 comments on commit b857462

Please sign in to comment.