diff --git a/project.gradle b/project.gradle index 7b66eb5..d93a5be 100644 --- a/project.gradle +++ b/project.gradle @@ -30,8 +30,7 @@ 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.google.guava", name: "guava", version: "28.1-android"); - implementation(group: "com.github.java-json-tools", name: "msg-simple", version: "1.2-SNAPSHOT"); + 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") { exclude(group: "junit", module: "junit"); @@ -51,7 +50,6 @@ javadoc { links("https://docs.oracle.com/javase/7/docs/api/"); links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.1/"); links("https://fasterxml.github.io/jackson-databind/javadoc/2.2.0/"); - links("https://www.javadoc.io/doc/com.google.guava/guava/28.1-android/"); links("https://java-json-tools.github.io/msg-simple/"); } } diff --git a/src/main/java/com/github/fge/jackson/JacksonUtils.java b/src/main/java/com/github/fge/jackson/JacksonUtils.java index 74c4773..85c41ff 100644 --- a/src/main/java/com/github/fge/jackson/JacksonUtils.java +++ b/src/main/java/com/github/fge/jackson/JacksonUtils.java @@ -29,10 +29,11 @@ import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.google.common.collect.Maps; import java.io.IOException; import java.io.StringWriter; +import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -94,11 +95,11 @@ public static JsonNodeFactory nodeFactory() */ public static Map asMap(final JsonNode node) { - final Map ret = Maps.newHashMap(); if (!node.isObject()) - return ret; + return Collections.emptyMap(); final Iterator> iterator = node.fields(); + final Map ret = new HashMap(); Map.Entry entry; diff --git a/src/main/java/com/github/fge/jackson/JsonLoader.java b/src/main/java/com/github/fge/jackson/JsonLoader.java index 0acecbf..5a3467b 100644 --- a/src/main/java/com/github/fge/jackson/JsonLoader.java +++ b/src/main/java/com/github/fge/jackson/JsonLoader.java @@ -20,11 +20,8 @@ package com.github.fge.jackson; import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Preconditions; -import com.google.common.io.Closer; import javax.annotation.Nonnull; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -74,50 +71,44 @@ private JsonLoader() public static JsonNode fromResource(@Nonnull final String resource) throws IOException { - Preconditions.checkNotNull(resource); - Preconditions.checkArgument(resource.startsWith("/"), - "resource path does not start with a '/'"); + if (resource == null) { + throw new NullPointerException(); + } + if (!resource.startsWith("/")) { + throw new IllegalArgumentException("resource path does not start with a '/'"); + } URL url; url = JsonLoader.class.getResource(resource); if (url == null) { - final ClassLoader classLoader = firstNonNull( - Thread.currentThread().getContextClassLoader(), - JsonLoader.class.getClassLoader() - ); + final ClassLoader classLoader; + if (Thread.currentThread().getContextClassLoader() != null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } else if (JsonLoader.class.getClassLoader() != null) { + classLoader = JsonLoader.class.getClassLoader(); + } else { + throw new NullPointerException(); + } final String s = INITIAL_SLASH.matcher(resource).replaceFirst(""); url = classLoader.getResource(s); } if (url == null) throw new IOException("resource " + resource + " not found"); - final Closer closer = Closer.create(); final JsonNode ret; - final InputStream in; + InputStream in = null; try { - in = closer.register(url.openStream()); + in = url.openStream(); ret = READER.fromInputStream(in); } finally { - closer.close(); + if (in != null) { + in.close(); + } } return ret; } - /** - * Returns the first non-null parameter. - * - * Implementation note: Avoids the Guava method of the same name, to mitigate 'Dependency Hell'. - * This can be replaced by {@code MoreObjects.firstNonNull} when moving to Guava >= 18.0 - * (Tip: Guava 20 seems like a good choice if Java 6 support is still necessary.) - * - * @throws NullPointerException if both are null. - */ - private static ClassLoader firstNonNull(ClassLoader first, ClassLoader second) - { - return first != null ? first : Preconditions.checkNotNull(second); - } - /** * Read a {@link JsonNode} from an URL. * @@ -141,15 +132,16 @@ public static JsonNode fromURL(final URL url) public static JsonNode fromPath(final String path) throws IOException { - final Closer closer = Closer.create(); final JsonNode ret; - final FileInputStream in; + FileInputStream in = null; try { - in = closer.register(new FileInputStream(path)); + in = new FileInputStream(path); ret = READER.fromInputStream(in); } finally { - closer.close(); + if (in != null) { + in.close(); + } } return ret; @@ -166,15 +158,16 @@ public static JsonNode fromPath(final String path) public static JsonNode fromFile(final File file) throws IOException { - final Closer closer = Closer.create(); final JsonNode ret; - final FileInputStream in; + FileInputStream in = null; try { - in = closer.register(new FileInputStream(file)); + in = new FileInputStream(file); ret = READER.fromInputStream(in); } finally { - closer.close(); + if (in != null) { + in.close(); + } } return ret; diff --git a/src/main/java/com/github/fge/jackson/JsonNodeReader.java b/src/main/java/com/github/fge/jackson/JsonNodeReader.java index 61e5e50..2e6c622 100644 --- a/src/main/java/com/github/fge/jackson/JsonNodeReader.java +++ b/src/main/java/com/github/fge/jackson/JsonNodeReader.java @@ -30,7 +30,6 @@ import com.github.fge.Builder; import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.bundle.PropertiesBundle; -import com.google.common.io.Closer; import javax.annotation.Nonnull; import javax.annotation.concurrent.ThreadSafe; @@ -93,16 +92,20 @@ public JsonNodeReader() public JsonNode fromInputStream(final InputStream in) throws IOException { - final Closer closer = Closer.create(); - final JsonParser parser; - final MappingIterator iterator; + JsonParser parser = null; + MappingIterator iterator = null; try { - parser = closer.register(reader.getFactory().createParser(in)); + parser = reader.getFactory().createParser(in); iterator = reader.readValues(parser); - return readNode(closer.register(iterator)); + return readNode(iterator); } finally { - closer.close(); + if (parser != null) { + parser.close(); + } + if (iterator != null) { + iterator.close(); + } } } @@ -117,16 +120,20 @@ public JsonNode fromInputStream(final InputStream in) public JsonNode fromReader(final Reader r) throws IOException { - final Closer closer = Closer.create(); - final JsonParser parser; - final MappingIterator iterator; + JsonParser parser = null; + MappingIterator iterator = null; try { - parser = closer.register(reader.getFactory().createParser(r)); + parser = reader.getFactory().createParser(r); iterator = reader.readValues(parser); - return readNode(closer.register(iterator)); + return readNode(iterator); } finally { - closer.close(); + if (parser != null) { + parser.close(); + } + if (iterator != null) { + iterator.close(); + } } } diff --git a/src/main/java/com/github/fge/jackson/JsonNumEquals.java b/src/main/java/com/github/fge/jackson/JsonNumEquals.java index 011fe3d..f098d4b 100644 --- a/src/main/java/com/github/fge/jackson/JsonNumEquals.java +++ b/src/main/java/com/github/fge/jackson/JsonNumEquals.java @@ -20,15 +20,15 @@ package com.github.fge.jackson; import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Equivalence; -import com.google.common.collect.Sets; +import javax.annotation.Nullable; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; /** - * An {@link Equivalence} strategy for JSON Schema equality + * An {@code com.google.common.base.Equivalence} like strategy for JSON Schema equality * *

{@link JsonNode} does a pretty good job of obeying the {@link * Object#equals(Object) equals()}/{@link Object#hashCode() hashCode()} @@ -41,21 +41,50 @@ * kind of equality.

*/ public final class JsonNumEquals - extends Equivalence { - private static final Equivalence INSTANCE + private static final JsonNumEquals INSTANCE = new JsonNumEquals(); private JsonNumEquals() { } - public static Equivalence getInstance() + public static JsonNumEquals getInstance() { return INSTANCE; } - @Override + /** + * Returns {@code true} if the given objects are considered equivalent. + * + *

The {@code equivalent} method implements an equivalence relation on object references: + * + *

    + *
  • It is reflexive: for any reference {@code x}, including null, {@code + * equivalent(x, x)} returns {@code true}. + *
  • It is symmetric: for any references {@code x} and {@code y}, {@code + * equivalent(x, y) == equivalent(y, x)}. + *
  • It is transitive: 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}. + *
  • It is consistent: 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). + *
+ * @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); + } + protected boolean doEquivalent(final JsonNode a, final JsonNode b) { /* @@ -93,7 +122,31 @@ protected boolean doEquivalent(final JsonNode a, final JsonNode b) return typeA == NodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b); } - @Override + /** + * Returns a hash code for {@code t}. + * + *

The {@code hash} has the following properties: + *

    + *
  • It is consistent: 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. + *
  • It is distributable across equivalence: for any references {@code x} and {@code y}, + * if {@code equivalent(x, y)}, then {@code hash(x) == hash(y)}. It is not necessary + * that the hash be distributable across inequivalence. If {@code equivalence(x, y)} + * is false, {@code hash(x) == hash(y)} may still be true. + *
  • {@code hash(null)} is {@code 0}. + *
+ * @param t node to hash + * @return hash + */ + public final int hash(@Nullable JsonNode t) { + if (t == null) { + return 0; + } + return doHash(t); + } + protected int doHash(final JsonNode t) { /* @@ -183,13 +236,32 @@ private boolean objectEquals(final JsonNode a, final JsonNode b) /* * Grab the key set from the first node */ - final Set keys = Sets.newHashSet(a.fieldNames()); - + final Set keys = new HashSet(); + Iterator iterator1 = a.fieldNames(); + while (iterator1.hasNext()) { + final String next = iterator1.next(); + if (next != null) { + keys.add(next); + } else { + throw new NullPointerException(); + } + } +// final Set keys = Sets.newHashSet(a.fieldNames()); /* * 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 = Sets.newHashSet(b.fieldNames()); + final Set set = new HashSet(); + Iterator iterator2 = b.fieldNames(); + while (iterator2.hasNext()) { + final String next = iterator2.next(); + if (next != null) { + set.add(next); + } else { + throw new NullPointerException(); + } + } + if (!set.equals(keys)) return false; diff --git a/src/main/java/com/github/fge/jackson/NodeType.java b/src/main/java/com/github/fge/jackson/NodeType.java index 7fb14cd..ea15551 100644 --- a/src/main/java/com/github/fge/jackson/NodeType.java +++ b/src/main/java/com/github/fge/jackson/NodeType.java @@ -22,10 +22,10 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.MissingNode; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; /** @@ -98,13 +98,13 @@ public enum NodeType TOKEN_MAP.put(JsonToken.START_OBJECT, OBJECT); TOKEN_MAP.put(JsonToken.VALUE_STRING, STRING); - final ImmutableMap.Builder builder - = ImmutableMap.builder(); + final Map builder + = new HashMap(); for (final NodeType type: NodeType.values()) builder.put(type.name, type); - NAME_MAP = builder.build(); + NAME_MAP = Collections.unmodifiableMap(builder); } NodeType(final String name) @@ -140,8 +140,9 @@ public static NodeType getNodeType(final JsonNode node) { final JsonToken token = node.asToken(); final NodeType ret = TOKEN_MAP.get(token); - - Preconditions.checkNotNull(ret, "unhandled token type " + token); + if (ret == null) { + throw new NullPointerException("unhandled token type " + token); + } return ret; } 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 9f3a0ca..670e50b 100644 --- a/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java +++ b/src/main/java/com/github/fge/jackson/jsonpointer/JsonPointer.java @@ -22,10 +22,10 @@ import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.MissingNode; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import javax.annotation.concurrent.Immutable; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -44,7 +44,7 @@ public final class JsonPointer * The empty JSON Pointer */ private static final JsonPointer EMPTY - = new JsonPointer(ImmutableList.>of()); + = new JsonPointer(Collections.>emptyList()); /** * Return an empty JSON Pointer @@ -72,7 +72,7 @@ public static JsonPointer empty() */ public static JsonPointer of(final Object first, final Object... other) { - final List tokens = Lists.newArrayList(); + final List tokens = new ArrayList(); tokens.add(ReferenceToken.fromRaw(first.toString())); @@ -120,7 +120,14 @@ public JsonPointer append(final String raw) final ReferenceToken refToken = ReferenceToken.fromRaw(raw); final JsonNodeResolver resolver = new JsonNodeResolver(refToken); final List> list - = Lists.newArrayList(tokenResolvers); + = new ArrayList>(); + for (final TokenResolver tokenResolver : tokenResolvers) { + if (tokenResolver != null) { + list.add(tokenResolver); + } else { + throw new NullPointerException(); + } + } list.add(resolver); return new JsonPointer(list); } @@ -147,7 +154,14 @@ public JsonPointer append(final JsonPointer other) { BUNDLE.checkNotNull(other, "nullInput"); final List> list - = Lists.newArrayList(tokenResolvers); + = new ArrayList>(); + for (final TokenResolver tokenResolver : tokenResolvers) { + if (tokenResolver != null) { + list.add(tokenResolver); + } else { + throw new NullPointerException(); + } + } list.addAll(other.tokenResolvers); return new JsonPointer(list); } @@ -177,7 +191,7 @@ public JsonPointer parent() private static List> fromTokens( final List tokens) { - final List> list = Lists.newArrayList(); + 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/ReferenceToken.java b/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java index 47d9891..8fd7c1a 100644 --- a/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java +++ b/src/main/java/com/github/fge/jackson/jsonpointer/ReferenceToken.java @@ -21,10 +21,12 @@ import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.load.MessageBundles; -import com.google.common.collect.ImmutableList; -import java.nio.CharBuffer; import javax.annotation.concurrent.Immutable; +import java.nio.CharBuffer; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** @@ -54,14 +56,14 @@ public final class ReferenceToken /** * List of encoding characters in a cooked token */ - private static final ImmutableList ENCODED = ImmutableList.of('0', '1'); + private static final List ENCODED = Collections.unmodifiableList(Arrays.asList('0', '1')); /** * List of sequences to encode in a raw token * *

This list and {@link #ENCODED} have matching indices on purpose.

*/ - private static final ImmutableList DECODED = ImmutableList.of('~', '/'); + private static final List DECODED = Collections.unmodifiableList(Arrays.asList('~', '/')); /** * The cooked representation of that token 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 a493b9c..df82ef8 100644 --- a/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java +++ b/src/main/java/com/github/fge/jackson/jsonpointer/TreePointer.java @@ -26,12 +26,12 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.load.MessageBundles; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; +import javax.annotation.concurrent.ThreadSafe; +import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; -import javax.annotation.concurrent.ThreadSafe; /** * A pointer into a {@link TreeNode} @@ -92,7 +92,7 @@ protected TreePointer(final T missing, final List> tokenResolvers) { this.missing = missing; - this.tokenResolvers = ImmutableList.copyOf(tokenResolvers); + this.tokenResolvers = Collections.unmodifiableList(new ArrayList>(tokenResolvers)); } /** @@ -174,7 +174,7 @@ public final boolean equals(final Object obj) return false; if (this == obj) return true; - if (!(obj instanceof TreePointer)) + if (getClass() != obj.getClass()) return false; final TreePointer other = (TreePointer) obj; return tokenResolvers.equals(other.tokenResolvers); @@ -206,7 +206,7 @@ protected static List tokensFromInput(final String input) throws JsonPointerException { String s = BUNDLE.checkNotNull(input, "nullInput"); - final List ret = Lists.newArrayList(); + final List ret = new ArrayList(); String cooked; int index; char c; diff --git a/src/main/java/com/github/fge/jackson/package-info.java b/src/main/java/com/github/fge/jackson/package-info.java index 8cb501c..44641ad 100644 --- a/src/main/java/com/github/fge/jackson/package-info.java +++ b/src/main/java/com/github/fge/jackson/package-info.java @@ -34,7 +34,7 @@ * com.fasterxml.jackson.databind.DeserializationFeature#USE_BIG_DECIMAL_FOR_FLOATS}. *

* - *

{@link com.github.fge.jackson.JsonNumEquals} is an {@link + *

{@link com.github.fge.jackson.JsonNumEquals} is an {@code * com.google.common.base.Equivalence} over {@link * com.fasterxml.jackson.databind.JsonNode} for recursive equivalence of JSON * number values.

diff --git a/src/main/java/overview.html b/src/main/java/overview.html index e17b4ed..710b41d 100644 --- a/src/main/java/overview.html +++ b/src/main/java/overview.html @@ -29,7 +29,7 @@

What this is

  • "single" JSON text read from sources;
  • -
  • an {@link com.google.common.base.Equivalence} over {@link +
  • an {@code com.google.common.base.Equivalence} over {@link com.fasterxml.jackson.databind.JsonNode} for numeric JSON values;
  • a generalized JSON pointer implementation over Jackson's {@link @@ -63,7 +63,7 @@

    JSON numeric equivalence

    and 1.0 yield different types of nodes.

    -

    This package provides an {@link com.google.common.base.Equivalence} to +

    This package provides an {@code com.google.common.base.Equivalence} to ensure that two numeric nodes are considered equivalent if their mathematical value is the same. See the javadoc for more information on how to use it.

    diff --git a/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java b/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java index 414ebd3..7a60cd4 100644 --- a/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java +++ b/src/test/java/com/github/fge/jackson/JsonNodeReaderTest.java @@ -24,8 +24,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.bundle.PropertiesBundle; -import com.google.common.base.Supplier; -import com.google.common.collect.Lists; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -35,6 +33,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.UnsupportedEncodingException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -71,7 +70,7 @@ public void readerIsClosedOnRead() @DataProvider public Iterator getMalformedData() { - final List list = Lists.newArrayList(); + final List list = new ArrayList(); list.add(new Object[] { "", "read.noContent"}); list.add(new Object[] { "[]{}", "read.trailingData"}); @@ -125,4 +124,21 @@ public Reader get() } }; } + + /** + * A class that can supply objects of a single type. Semantically, this could + * be a factory, generator, builder, closure, or something else entirely. No + * guarantees are implied by this interface. + * + * @author Harry Heymann + */ + public interface Supplier { + /** + * Retrieves an instance of the appropriate type. The returned object may or + * may not be a new instance, depending on the implementation. + * + * @return an instance of the appropriate type + */ + T get(); + } } diff --git a/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java b/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java index ea65f1a..cecb942 100644 --- a/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java +++ b/src/test/java/com/github/fge/jackson/JsonNumEqualsTest.java @@ -23,12 +23,12 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.Lists; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -49,7 +49,7 @@ public void initData() @DataProvider public Iterator getInputs() { - final List list = Lists.newArrayList(); + 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 c6f7333..ec03e32 100644 --- a/src/test/java/com/github/fge/jackson/SampleNodeProvider.java +++ b/src/test/java/com/github/fge/jackson/SampleNodeProvider.java @@ -21,15 +21,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.google.common.base.Function; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import java.math.BigDecimal; -import java.util.EnumSet; -import java.util.Iterator; -import java.util.Map; +import java.util.*; public final class SampleNodeProvider { @@ -41,7 +35,7 @@ private SampleNodeProvider() } static { - SAMPLE_DATA = Maps.newEnumMap(NodeType.class); + SAMPLE_DATA = new EnumMap(NodeType.class); SAMPLE_DATA.put(NodeType.ARRAY, FACTORY.arrayNode()); SAMPLE_DATA.put(NodeType.BOOLEAN, FACTORY.booleanNode(true)); @@ -58,18 +52,15 @@ private SampleNodeProvider() // differ... public static Iterator getSamples(final EnumSet types) { - final Map map = Maps.newEnumMap(SAMPLE_DATA); + final Map map = new EnumMap(SAMPLE_DATA); map.keySet().retainAll(types); - return FluentIterable.from(map.values()) - .transform(new Function() - { - @Override - public Object[] apply(final JsonNode input) - { - return new Object[] { input }; - } - }).iterator(); + final ArrayList samples = new ArrayList(); + for (final JsonNode input : map.values()) { + samples.add(new Object[] { input }); + } + + return samples.iterator(); } public static Iterator getSamplesExcept( @@ -87,6 +78,6 @@ public static Iterator getSamples(final NodeType first, public static Iterator getSamplesExcept(final NodeType first, final NodeType... other) { - return getSamples(Sets.complementOf(EnumSet.of(first, other))); + return getSamples(EnumSet.complementOf(EnumSet.of(first, other))); } } 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 eac5673..d4a042f 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/JsonNodeResolverTest.java @@ -26,10 +26,10 @@ import com.github.fge.jackson.JacksonUtils; import com.github.fge.jackson.NodeType; import com.github.fge.jackson.SampleNodeProvider; -import com.google.common.collect.Lists; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -104,7 +104,7 @@ public void resolvingArrayIndicesWorks() @DataProvider public Iterator invalidIndices() { - final List list = Lists.newArrayList(); + 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 c5145f7..c04fded 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/JsonPointerTest.java @@ -26,17 +26,13 @@ import com.github.fge.jackson.SampleNodeProvider; import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.load.MessageBundles; -import com.google.common.collect.Lists; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.EnumSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.testng.Assert.*; @@ -70,7 +66,7 @@ public void cannotAppendNullPointer() @DataProvider public Iterator rawPointers() { - final List list = Lists.newArrayList(); + final List list = new ArrayList(); final JsonNode testNode = testData.get("pointers"); final Map map = JacksonUtils.asMap(testNode); @@ -93,7 +89,7 @@ public void rawPointerResolvingWorks(final String input, @DataProvider public Iterator uriPointers() { - final List list = Lists.newArrayList(); + final List list = new ArrayList(); final JsonNode testNode = testData.get("uris"); final Map map = JacksonUtils.asMap(testNode); @@ -185,7 +181,7 @@ public void staticConstructionFromTokensWorks() @DataProvider public Iterator parentTestData() { - final List list = Lists.newArrayList(); + 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/ReferenceTokenTest.java b/src/test/java/com/github/fge/jackson/jsonpointer/ReferenceTokenTest.java index 42a8bcc..bd93eb9 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/ReferenceTokenTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/ReferenceTokenTest.java @@ -21,10 +21,11 @@ import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.load.MessageBundles; -import com.google.common.collect.ImmutableList; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import static org.testng.Assert.*; @@ -81,14 +82,14 @@ public void illegalEscapeRaisesTheAppropriateException() @DataProvider public Iterator cookedRaw() { - return ImmutableList.of( + return Collections.unmodifiableList(Arrays.asList( new Object[] { "~0", "~" }, new Object[] { "~1", "/" }, new Object[] { "", "" }, new Object[] { "~0user", "~user" }, new Object[] { "foobar", "foobar" }, new Object[] { "~1var~1lib~1mysql", "/var/lib/mysql" } - ).iterator(); + )).iterator(); } @Test(dataProvider = "cookedRaw") @@ -106,11 +107,11 @@ public void fromCookedOrFromRawYieldsSameResults(final String cooked, @DataProvider public Iterator indices() { - return ImmutableList.of( + return Collections.unmodifiableList(Arrays.asList( new Object[] { 0, "0" }, new Object[] { -1, "-1" }, new Object[]{ 13, "13" } - ).iterator(); + )).iterator(); } @Test(dataProvider = "indices") 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 676b52b..a42a406 100644 --- a/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java +++ b/src/test/java/com/github/fge/jackson/jsonpointer/TreePointerTest.java @@ -22,11 +22,9 @@ import com.fasterxml.jackson.core.TreeNode; import com.github.fge.msgsimple.bundle.MessageBundle; import com.github.fge.msgsimple.load.MessageBundles; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; import org.testng.annotations.Test; -import java.util.List; +import java.util.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -65,7 +63,7 @@ public void buildingTokenListIsUnfazedByAnEmptyInput() throws JsonPointerException { assertEquals(TreePointer.tokensFromInput(""), - ImmutableList.of()); + Collections.emptyList()); } @Test @@ -73,7 +71,7 @@ public void buildingTokenListIsUnfazedByEmptyToken() throws JsonPointerException { final List expected - = ImmutableList.of(ReferenceToken.fromCooked("")); + = Collections.singletonList(ReferenceToken.fromCooked("")); final List actual = TreePointer.tokensFromInput("/"); assertEquals(actual, expected); @@ -83,11 +81,11 @@ public void buildingTokenListIsUnfazedByEmptyToken() public void tokenListRespectsOrder() throws JsonPointerException { - final List expected = ImmutableList.of( + final List expected = Collections.unmodifiableList(Arrays.asList( ReferenceToken.fromRaw("/"), ReferenceToken.fromRaw("~"), ReferenceToken.fromRaw("x") - ); + )); final List actual = TreePointer.tokensFromInput("/~1/~0/x"); @@ -98,11 +96,11 @@ public void tokenListRespectsOrder() public void tokenListAccountsForEmptyTokens() throws JsonPointerException { - final List expected = ImmutableList.of( + final List expected = Collections.unmodifiableList(Arrays.asList( ReferenceToken.fromRaw("a"), ReferenceToken.fromRaw(""), ReferenceToken.fromRaw("b") - ); + )); final List actual = TreePointer.tokensFromInput("/a//b"); @@ -121,7 +119,7 @@ public void gettingTraversalResultGoesNoFurtherThanFirstMissing() when(token1.get(any(TreeNode.class))).thenReturn(null); final DummyPointer ptr = new DummyPointer(missing, - ImmutableList.of(token1, token2)); + Collections.unmodifiableList(Arrays.asList(token1, token2))); final TreeNode node = mock(TreeNode.class); final TreeNode ret = ptr.get(node); @@ -143,7 +141,7 @@ public void gettingPathOfMissingNodeReturnsMissingNode() when(token1.get(any(TreeNode.class))).thenReturn(null); final DummyPointer ptr = new DummyPointer(missing, - ImmutableList.of(token1, token2)); + Collections.unmodifiableList(Arrays.asList(token1, token2))); final TreeNode node = mock(TreeNode.class); final TreeNode ret = ptr.path(node); @@ -156,7 +154,7 @@ public void gettingPathOfMissingNodeReturnsMissingNode() @Test public void treePointerCanTellWhetherItIsEmpty() { - final List> list = Lists.newArrayList(); + final List> list = new ArrayList>(); assertTrue(new DummyPointer(null, list).isEmpty()); @@ -170,7 +168,7 @@ public void treePointerCanTellWhetherItIsEmpty() @Test public void treeIsUnalteredWhenOriginalListIsAltered() { - final List> list = Lists.newArrayList(); + final List> list = new ArrayList>(); final DummyPointer dummy = new DummyPointer(null, list); @SuppressWarnings("unchecked")