java: NilType::create() returns NilType's one and only instance

This commit is contained in:
frsyuki 2010-08-19 00:54:23 +09:00
parent 193a739749
commit 1d17836b7d
3 changed files with 8 additions and 6 deletions

View File

@ -23,7 +23,7 @@ import java.util.Map;
import java.math.BigInteger;
public abstract class MessagePackObject implements Cloneable, MessagePackable {
public boolean isNull() {
public boolean isNil() {
return false;
}

View File

@ -21,14 +21,16 @@ import java.io.IOException;
import org.msgpack.*;
public class NilType extends MessagePackObject {
private static NilType instance = new NilType();
private final static NilType INSTANCE = new NilType();
public static NilType create() {
return instance;
return INSTANCE;
}
private NilType() { }
@Override
public boolean isNull() {
public boolean isNil() {
return true;
}
@ -52,7 +54,7 @@ public class NilType extends MessagePackObject {
@Override
public Object clone() {
return new NilType();
return INSTANCE;
}
}

View File

@ -130,7 +130,7 @@ public class TestPackUnpack {
ByteArrayOutputStream out = new ByteArrayOutputStream();
new Packer(out).packNil();
MessagePackObject obj = unpackOne(out);
assertTrue(obj.isNull());
assertTrue(obj.isNil());
}
@Test