001/*
002 * Copyright 2015-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2015-2022 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2015-2022 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.util.json;
037
038
039
040import com.unboundid.util.NotMutable;
041import com.unboundid.util.NotNull;
042import com.unboundid.util.Nullable;
043import com.unboundid.util.ThreadSafety;
044import com.unboundid.util.ThreadSafetyLevel;
045
046
047
048/**
049 * This class provides an implementation of a JSON value that represents a null
050 * value.  The string representation of the null value is {@code null} in all
051 * lowercase and without any quotation marks.
052 */
053@NotMutable()
054@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
055public final class JSONNull
056       extends JSONValue
057{
058  /**
059   * A pre-allocated JSON null value object.
060   */
061  @NotNull public static final JSONNull NULL = new JSONNull();
062
063
064
065  /**
066   * The serial version UID for this serializable class.
067   */
068  private static final long serialVersionUID = -8359265286375144526L;
069
070
071
072  /**
073   * Creates a new JSON value capable of representing a {@code null} value.
074   */
075  public JSONNull()
076  {
077  }
078
079
080
081  /**
082   * {@inheritDoc}
083   */
084  @Override()
085  public int hashCode()
086  {
087    return 1;
088  }
089
090
091
092  /**
093   * {@inheritDoc}
094   */
095  @Override()
096  public boolean equals(@Nullable final Object o)
097  {
098    return ((o == this) || (o instanceof JSONNull));
099  }
100
101
102
103  /**
104   * {@inheritDoc}
105   */
106  @Override()
107  public boolean equals(@NotNull final JSONValue v,
108                        final boolean ignoreFieldNameCase,
109                        final boolean ignoreValueCase,
110                        final boolean ignoreArrayOrder)
111  {
112    return (v instanceof JSONNull);
113  }
114
115
116
117  /**
118   * Retrieves a string representation of this null value as it should appear
119   * in a JSON object.  Null values will always have a string representation of
120   * "{@code null}" (without the surrounding quotes).
121   *
122   * @return  A string representation of this null value as it should appear
123   *          in a JSON object.
124   */
125  @Override()
126  @NotNull()
127  public String toString()
128  {
129    return "null";
130  }
131
132
133
134  /**
135   * Appends a string representation of this null value as it should appear
136   * in a JSON object to the provided buffer.  Null values will always have a
137   * string representation of "{@code null}" (without the surrounding quotes).
138   *
139   * @param  buffer  The buffer to which the information should be appended.
140   */
141  @Override()
142  public void toString(@NotNull final StringBuilder buffer)
143  {
144    buffer.append("null");
145  }
146
147
148
149  /**
150   * Retrieves a single-line string representation of this null value as it
151   * should appear in a JSON object.  Null values will always have a string
152   * representation of "{@code null}" (without the surrounding quotes).
153   *
154   * @return  A single-line string representation of this null value as it
155   *          should appear in a JSON object.
156   */
157  @Override()
158  @NotNull()
159  public String toSingleLineString()
160  {
161    return "null";
162  }
163
164
165
166  /**
167   * Appends a single-line string representation of this null value as it should
168   * appear in a JSON object to the provided buffer.  Null values will always
169   * have a string representation of "{@code null}" (without the surrounding
170   * quotes).
171   *
172   * @param  buffer  The buffer to which the information should be appended.
173   */
174  @Override()
175  public void toSingleLineString(@NotNull final StringBuilder buffer)
176  {
177    buffer.append("null");
178  }
179
180
181
182  /**
183   * Retrieves a normalized string representation of this null value as it
184   * should appear in a JSON object.  Null values will always have a string
185   * representation of "{@code null}" (without the surrounding quotes).
186   *
187   * @return  A normalized string representation of this null value as it
188   *          should appear in a JSON object.
189   */
190  @Override()
191  @NotNull()
192  public String toNormalizedString()
193  {
194    return "null";
195  }
196
197
198
199  /**
200   * Appends a normalized string representation of this null value as it should
201   * appear in a JSON object to the provided buffer.  Null values will always
202   * have a string representation of "{@code null}" (without the surrounding
203   * quotes).
204   *
205   * @param  buffer  The buffer to which the information should be appended.
206   */
207  @Override()
208  public void toNormalizedString(@NotNull final StringBuilder buffer)
209  {
210    buffer.append("null");
211  }
212
213
214
215  /**
216   * Retrieves a normalized string representation of this null value as it
217   * should appear in a JSON object.  Null values will always have a string
218   * representation of "{@code null}" (without the surrounding quotes).
219   *
220   * @param  ignoreFieldNameCase  Indicates whether field names should be
221   *                              treated in a case-sensitive (if {@code false})
222   *                              or case-insensitive (if {@code true}) manner.
223   * @param  ignoreValueCase      Indicates whether string field values should
224   *                              be treated in a case-sensitive (if
225   *                              {@code false}) or case-insensitive (if
226   *                              {@code true}) manner.
227   * @param  ignoreArrayOrder     Indicates whether the order of elements in an
228   *                              array should be considered significant (if
229   *                              {@code false}) or insignificant (if
230   *                              {@code true}).
231   *
232   * @return  A normalized string representation of this null value as it
233   *          should appear in a JSON object.
234   */
235  @Override()
236  @NotNull()
237  public String toNormalizedString(final boolean ignoreFieldNameCase,
238                                   final boolean ignoreValueCase,
239                                   final boolean ignoreArrayOrder)
240  {
241    return "null";
242  }
243
244
245
246  /**
247   * Appends a normalized string representation of this null value as it should
248   * appear in a JSON object to the provided buffer.  Null values will always
249   * have a string representation of "{@code null}" (without the surrounding
250   * quotes).
251   *
252   * @param  buffer               The buffer to which the information should be
253   *                              appended.
254   * @param  ignoreFieldNameCase  Indicates whether field names should be
255   *                              treated in a case-sensitive (if {@code false})
256   *                              or case-insensitive (if {@code true}) manner.
257   * @param  ignoreValueCase      Indicates whether string field values should
258   *                              be treated in a case-sensitive (if
259   *                              {@code false}) or case-insensitive (if
260   *                              {@code true}) manner.
261   * @param  ignoreArrayOrder     Indicates whether the order of elements in an
262   *                              array should be considered significant (if
263   *                              {@code false}) or insignificant (if
264   *                              {@code true}).
265   */
266  @Override()
267  public void toNormalizedString(@NotNull final StringBuilder buffer,
268                                 final boolean ignoreFieldNameCase,
269                                 final boolean ignoreValueCase,
270                                 final boolean ignoreArrayOrder)
271  {
272    buffer.append("null");
273  }
274
275
276
277  /**
278   * {@inheritDoc}
279   */
280  @Override()
281  public void appendToJSONBuffer(@NotNull final JSONBuffer buffer)
282  {
283    buffer.appendNull();
284  }
285
286
287
288  /**
289   * {@inheritDoc}
290   */
291  @Override()
292  public void appendToJSONBuffer(@NotNull final String fieldName,
293                                 @NotNull final JSONBuffer buffer)
294  {
295    buffer.appendNull(fieldName);
296  }
297}