|
20 | 20 | package com.github.fge.jackson; |
21 | 21 |
|
22 | 22 | import com.fasterxml.jackson.databind.JsonNode; |
| 23 | +import com.google.common.base.Equivalence; |
23 | 24 |
|
24 | | -import javax.annotation.Nullable; |
25 | 25 | import java.util.HashSet; |
26 | 26 | import java.util.Iterator; |
27 | 27 | import java.util.Map; |
|
41 | 41 | * kind of equality.</p> |
42 | 42 | */ |
43 | 43 | public final class JsonNumEquals |
| 44 | + extends Equivalence<JsonNode> |
44 | 45 | { |
45 | | - private static final JsonNumEquals INSTANCE |
| 46 | + private static final Equivalence<JsonNode> INSTANCE |
46 | 47 | = new JsonNumEquals(); |
47 | 48 |
|
48 | 49 | private JsonNumEquals() |
49 | 50 | { |
50 | 51 | } |
51 | 52 |
|
52 | | - public static JsonNumEquals getInstance() |
| 53 | + public static Equivalence<JsonNode> getInstance() |
53 | 54 | { |
54 | 55 | return INSTANCE; |
55 | 56 | } |
56 | 57 |
|
57 | | - /** |
58 | | - * Returns {@code true} if the given objects are considered equivalent. |
59 | | - * |
60 | | - * <p>The {@code equivalent} method implements an equivalence relation on object references: |
61 | | - * |
62 | | - * <ul> |
63 | | - * <li>It is <i>reflexive</i>: for any reference {@code x}, including null, {@code |
64 | | - * equivalent(x, x)} returns {@code true}. |
65 | | - * <li>It is <i>symmetric</i>: for any references {@code x} and {@code y}, {@code |
66 | | - * equivalent(x, y) == equivalent(y, x)}. |
67 | | - * <li>It is <i>transitive</i>: for any references {@code x}, {@code y}, and {@code z}, if |
68 | | - * {@code equivalent(x, y)} returns {@code true} and {@code equivalent(y, z)} returns {@code |
69 | | - * true}, then {@code equivalent(x, z)} returns {@code true}. |
70 | | - * <li>It is <i>consistent</i>: for any references {@code x} and {@code y}, multiple invocations |
71 | | - * of {@code equivalent(x, y)} consistently return {@code true} or consistently return {@code |
72 | | - * false} (provided that neither {@code x} nor {@code y} is modified). |
73 | | - * </ul> |
74 | | - * @param a x |
75 | | - * @param b y |
76 | | - * @return whether nodes are equal according to IETF RFCs |
77 | | - */ |
78 | | - public final boolean equivalent(@Nullable JsonNode a, @Nullable JsonNode b) { |
79 | | - if (a == b) { |
80 | | - return true; |
81 | | - } |
82 | | - if (a == null || b == null) { |
83 | | - return false; |
84 | | - } |
85 | | - return doEquivalent(a, b); |
86 | | - } |
87 | | - |
| 58 | + @Override |
88 | 59 | protected boolean doEquivalent(final JsonNode a, final JsonNode b) |
89 | 60 | { |
90 | 61 | /* |
@@ -122,31 +93,7 @@ protected boolean doEquivalent(final JsonNode a, final JsonNode b) |
122 | 93 | return typeA == NodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b); |
123 | 94 | } |
124 | 95 |
|
125 | | - /** |
126 | | - * Returns a hash code for {@code t}. |
127 | | - * |
128 | | - * <p>The {@code hash} has the following properties: |
129 | | - * <ul> |
130 | | - * <li>It is <i>consistent</i>: for any reference {@code x}, multiple invocations of |
131 | | - * {@code hash(x}} consistently return the same value provided {@code x} remains unchanged |
132 | | - * according to the definition of the equivalence. The hash need not remain consistent from |
133 | | - * one execution of an application to another execution of the same application. |
134 | | - * <li>It is <i>distributable across equivalence</i>: for any references {@code x} and {@code y}, |
135 | | - * if {@code equivalent(x, y)}, then {@code hash(x) == hash(y)}. It is <i>not</i> necessary |
136 | | - * that the hash be distributable across <i>inequivalence</i>. If {@code equivalence(x, y)} |
137 | | - * is false, {@code hash(x) == hash(y)} may still be true. |
138 | | - * <li>{@code hash(null)} is {@code 0}. |
139 | | - * </ul> |
140 | | - * @param t node to hash |
141 | | - * @return hash |
142 | | - */ |
143 | | - public final int hash(@Nullable JsonNode t) { |
144 | | - if (t == null) { |
145 | | - return 0; |
146 | | - } |
147 | | - return doHash(t); |
148 | | - } |
149 | | - |
| 96 | + @Override |
150 | 97 | protected int doHash(final JsonNode t) |
151 | 98 | { |
152 | 99 | /* |
|
0 commit comments