Start using JsonNull.INSTANCE everywhere and remove creation method.
This commit is contained in:
parent
8fd4072f9b
commit
c9ee7adcc5
@ -62,18 +62,4 @@ public final class JsonNull extends JsonElement {
|
|||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return this == other || other instanceof JsonNull;
|
return this == other || other instanceof JsonNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creation method used to return an instance of a {@link JsonNull}. To reduce the memory
|
|
||||||
* footprint, a single object has been created for this class; therefore the same instance is
|
|
||||||
* being returned for each invocation of this method. This method is kept private since we
|
|
||||||
* prefer the users to use {@link JsonNull#JsonNull()} which is similar to how other JsonElements
|
|
||||||
* are created. Note that all instances of JsonNull return true for {@link #equals(Object)}
|
|
||||||
* when compared to each other.
|
|
||||||
*
|
|
||||||
* @return a instance of a {@link JsonNull}
|
|
||||||
*/
|
|
||||||
static JsonNull createJsonNull() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.common.MoreAsserts;
|
import com.google.gson.common.MoreAsserts;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +29,6 @@ public final class JsonNullTest extends TestCase {
|
|||||||
public void testEqualsAndHashcode() {
|
public void testEqualsAndHashcode() {
|
||||||
MoreAsserts.assertEqualsAndHashCode(new JsonNull(), new JsonNull());
|
MoreAsserts.assertEqualsAndHashCode(new JsonNull(), new JsonNull());
|
||||||
MoreAsserts.assertEqualsAndHashCode(new JsonNull(), JsonNull.INSTANCE);
|
MoreAsserts.assertEqualsAndHashCode(new JsonNull(), JsonNull.INSTANCE);
|
||||||
MoreAsserts.assertEqualsAndHashCode(new JsonNull(), JsonNull.createJsonNull());
|
MoreAsserts.assertEqualsAndHashCode(JsonNull.INSTANCE, JsonNull.INSTANCE);
|
||||||
MoreAsserts.assertEqualsAndHashCode(JsonNull.createJsonNull(), JsonNull.createJsonNull());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.google.gson;
|
package com.google.gson;
|
||||||
|
|
||||||
import com.google.gson.common.MoreAsserts;
|
import com.google.gson.common.MoreAsserts;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,12 +57,12 @@ public class JsonObjectTest extends TestCase {
|
|||||||
public void testAddingNullOrEmptyPropertyName() throws Exception {
|
public void testAddingNullOrEmptyPropertyName() throws Exception {
|
||||||
JsonObject jsonObj = new JsonObject();
|
JsonObject jsonObj = new JsonObject();
|
||||||
try {
|
try {
|
||||||
jsonObj.add(null, JsonNull.createJsonNull());
|
jsonObj.add(null, JsonNull.INSTANCE);
|
||||||
fail("Should not allow null property names.");
|
fail("Should not allow null property names.");
|
||||||
} catch (NullPointerException expected) { }
|
} catch (NullPointerException expected) { }
|
||||||
|
|
||||||
jsonObj.add("", JsonNull.createJsonNull());
|
jsonObj.add("", JsonNull.INSTANCE);
|
||||||
jsonObj.add(" \t", JsonNull.createJsonNull());
|
jsonObj.add(" \t", JsonNull.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddingBooleanProperties() throws Exception {
|
public void testAddingBooleanProperties() throws Exception {
|
||||||
|
Loading…
Reference in New Issue
Block a user