Incorporated comments from r726
This commit is contained in:
parent
a147164852
commit
feb9617bf0
@ -297,7 +297,7 @@ public final class JsonArray extends JsonElement implements Iterable<JsonElement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof JsonArray && ((JsonArray) o).elements.equals(elements);
|
return (o == this) || (o instanceof JsonArray && ((JsonArray) o).elements.equals(elements));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,7 +53,7 @@ public final class JsonNull extends JsonElement {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return other instanceof JsonNull;
|
return this == other || other instanceof JsonNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,8 +191,8 @@ public final class JsonObject extends JsonElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof JsonObject
|
return (o == this) || (o instanceof JsonObject
|
||||||
&& ((JsonObject) o).members.equals(members);
|
&& ((JsonObject) o).members.equals(members));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -356,6 +356,8 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
}
|
}
|
||||||
if (isFloatingPoint(this) && isFloatingPoint(other)) {
|
if (isFloatingPoint(this) && isFloatingPoint(other)) {
|
||||||
double a = getAsNumber().doubleValue();
|
double a = getAsNumber().doubleValue();
|
||||||
|
// Java standard types other than double return true for two NaN. So, need
|
||||||
|
// special handling for double.
|
||||||
double b = other.getAsNumber().doubleValue();
|
double b = other.getAsNumber().doubleValue();
|
||||||
return a == b || (Double.isNaN(a) && Double.isNaN(b));
|
return a == b || (Double.isNaN(a) && Double.isNaN(b));
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ public final class JsonArrayTest extends TestCase {
|
|||||||
JsonArray a = new JsonArray();
|
JsonArray a = new JsonArray();
|
||||||
JsonArray b = new JsonArray();
|
JsonArray b = new JsonArray();
|
||||||
|
|
||||||
|
assertEquals(a, a);
|
||||||
|
|
||||||
a.add(new JsonObject());
|
a.add(new JsonObject());
|
||||||
assertFalse(a.equals(b));
|
assertFalse(a.equals(b));
|
||||||
assertFalse(b.equals(a));
|
assertFalse(b.equals(a));
|
||||||
|
@ -138,6 +138,8 @@ public class JsonObjectTest extends TestCase {
|
|||||||
JsonObject a = new JsonObject();
|
JsonObject a = new JsonObject();
|
||||||
JsonObject b = new JsonObject();
|
JsonObject b = new JsonObject();
|
||||||
|
|
||||||
|
assertEquals(a, a);
|
||||||
|
|
||||||
a.add("foo", new JsonObject());
|
a.add("foo", new JsonObject());
|
||||||
assertFalse(a.equals(b));
|
assertFalse(a.equals(b));
|
||||||
assertFalse(b.equals(a));
|
assertFalse(b.equals(a));
|
||||||
|
@ -186,6 +186,15 @@ public class JsonPrimitiveTest extends TestCase {
|
|||||||
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(5L), new JsonPrimitive(5L));
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(5L), new JsonPrimitive(5L));
|
||||||
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive('a'), new JsonPrimitive('a'));
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive('a'), new JsonPrimitive('a'));
|
||||||
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Float.NaN), new JsonPrimitive(Float.NaN));
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Float.NaN), new JsonPrimitive(Float.NaN));
|
||||||
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Float.NEGATIVE_INFINITY),
|
||||||
|
new JsonPrimitive(Float.NEGATIVE_INFINITY));
|
||||||
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Float.POSITIVE_INFINITY),
|
||||||
|
new JsonPrimitive(Float.POSITIVE_INFINITY));
|
||||||
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Double.NaN), new JsonPrimitive(Double.NaN));
|
||||||
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Double.NEGATIVE_INFINITY),
|
||||||
|
new JsonPrimitive(Double.NEGATIVE_INFINITY));
|
||||||
|
MoreAsserts.assertEqualsAndHashCode(new JsonPrimitive(Double.POSITIVE_INFINITY),
|
||||||
|
new JsonPrimitive(Double.POSITIVE_INFINITY));
|
||||||
assertFalse(new JsonPrimitive("a").equals(new JsonPrimitive("b")));
|
assertFalse(new JsonPrimitive("a").equals(new JsonPrimitive("b")));
|
||||||
assertFalse(new JsonPrimitive(true).equals(new JsonPrimitive(false)));
|
assertFalse(new JsonPrimitive(true).equals(new JsonPrimitive(false)));
|
||||||
assertFalse(new JsonPrimitive(0).equals(new JsonPrimitive(1)));
|
assertFalse(new JsonPrimitive(0).equals(new JsonPrimitive(1)));
|
||||||
|
Loading…
Reference in New Issue
Block a user