comparison src/main/java/org/msgpack/type/NilValue.java @ 0:cb825acd883a

first commit
author sugi
date Sat, 18 Oct 2014 15:06:15 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cb825acd883a
1 //
2 // MessagePack for Java
3 //
4 // Copyright (C) 2009 - 2013 FURUHASHI Sadayuki
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 package org.msgpack.type;
19
20 import java.io.IOException;
21 import org.msgpack.packer.Packer;
22
23 public class NilValue extends AbstractValue {
24 private NilValue() {
25 }
26
27 private static NilValue instance = new NilValue();
28
29 static NilValue getInstance() {
30 return instance;
31 }
32
33 @Override
34 public ValueType getType() {
35 return ValueType.NIL;
36 }
37
38 @Override
39 public boolean isNilValue() {
40 return true;
41 }
42
43 @Override
44 public NilValue asNilValue() {
45 return this;
46 }
47
48 @Override
49 public String toString() {
50 return "null";
51 }
52
53 @Override
54 public StringBuilder toString(StringBuilder sb) {
55 return sb.append("null");
56 }
57
58 @Override
59 public void writeTo(Packer pk) throws IOException {
60 pk.writeNil();
61 }
62
63 @Override
64 public boolean equals(Object o) {
65 if (o == this) {
66 return true;
67 }
68 if (!(o instanceof Value)) {
69 return false;
70 }
71 return ((Value) o).isNilValue();
72 }
73
74 @Override
75 public int hashCode() {
76 return 0;
77 }
78 }