001 /*
002 * Copyright 2015-2016 UnboundID Corp.
003 * All Rights Reserved.
004 */
005 /*
006 * Copyright (C) 2015-2016 UnboundID Corp.
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021 package com.unboundid.util.json;
022
023
024
025 import com.unboundid.util.NotMutable;
026 import com.unboundid.util.ThreadSafety;
027 import com.unboundid.util.ThreadSafetyLevel;
028
029
030
031 /**
032 * This class provides an implementation of a JSON value that represents a null
033 * value. The string representation of the null value is {@code null} in all
034 * lowercase and without any quotation marks.
035 */
036 @NotMutable()
037 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
038 public final class JSONNull
039 extends JSONValue
040 {
041 /**
042 * A pre-allocated JSON null value object.
043 */
044 public static final JSONNull NULL = new JSONNull();
045
046
047
048 /**
049 * The serial version UID for this serializable class.
050 */
051 private static final long serialVersionUID = -8359265286375144526L;
052
053
054
055 /**
056 * Creates a new JSON value capable of representing a {@code null} value.
057 */
058 public JSONNull()
059 {
060 }
061
062
063
064 /**
065 * {@inheritDoc}
066 */
067 @Override()
068 public int hashCode()
069 {
070 return 1;
071 }
072
073
074
075 /**
076 * {@inheritDoc}
077 */
078 @Override()
079 public boolean equals(final Object o)
080 {
081 return ((o == this) || (o instanceof JSONNull));
082 }
083
084
085
086 /**
087 * {@inheritDoc}
088 */
089 @Override()
090 public boolean equals(final JSONValue v, final boolean ignoreFieldNameCase,
091 final boolean ignoreValueCase,
092 final boolean ignoreArrayOrder)
093 {
094 return (v instanceof JSONNull);
095 }
096
097
098
099 /**
100 * {@inheritDoc}
101 */
102 @Override()
103 public String toString()
104 {
105 return "null";
106 }
107
108
109
110 /**
111 * {@inheritDoc}
112 */
113 @Override()
114 public void toString(final StringBuilder buffer)
115 {
116 buffer.append("null");
117 }
118
119
120
121 /**
122 * {@inheritDoc}
123 */
124 @Override()
125 public String toSingleLineString()
126 {
127 return "null";
128 }
129
130
131
132 /**
133 * {@inheritDoc}
134 */
135 @Override()
136 public void toSingleLineString(final StringBuilder buffer)
137 {
138 buffer.append("null");
139 }
140
141
142
143 /**
144 * {@inheritDoc}
145 */
146 @Override()
147 public String toNormalizedString()
148 {
149 return "null";
150 }
151
152
153
154 /**
155 * {@inheritDoc}
156 */
157 @Override()
158 public void toNormalizedString(final StringBuilder buffer)
159 {
160 buffer.append("null");
161 }
162
163
164
165 /**
166 * {@inheritDoc}
167 */
168 @Override()
169 public void appendToJSONBuffer(final JSONBuffer buffer)
170 {
171 buffer.appendNull();
172 }
173
174
175
176 /**
177 * {@inheritDoc}
178 */
179 @Override()
180 public void appendToJSONBuffer(final String fieldName,
181 final JSONBuffer buffer)
182 {
183 buffer.appendNull(fieldName);
184 }
185 }