/
ImmutableJsonObjectNull.java
executable file
·205 lines (167 loc) · 4.8 KB
/
ImmutableJsonObjectNull.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.json;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
* An immutable implementation of the NULL literal as JsonObject.
*/
@Immutable
final class ImmutableJsonObjectNull extends AbstractJsonValue implements JsonObject, JsonNull {
@Nullable private static ImmutableJsonObjectNull instance = null;
private ImmutableJsonObjectNull() {
super();
}
/**
* Returns an instance of {@code ImmutableJsonObjectNull}.
*
* @return the instance.
*/
public static ImmutableJsonObjectNull getInstance() {
ImmutableJsonObjectNull result = instance;
if (null == result) {
result = new ImmutableJsonObjectNull();
instance = result;
}
return result;
}
@Override
public boolean isNull() {
return true;
}
@Override
public boolean isObject() {
return true;
}
@Override
public ImmutableJsonObjectNull asObject() {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final int value) {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final long value) {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final double value) {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final boolean value) {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final String value) {
return this;
}
@Override
public ImmutableJsonObjectNull setValue(final CharSequence key, final JsonValue value) {
return this;
}
@Override
public <T> ImmutableJsonObjectNull set(final JsonFieldDefinition<T> fieldDefinition, @Nullable final T value) {
return this;
}
@Override
public ImmutableJsonObjectNull set(final JsonField field) {
return this;
}
@Override
public ImmutableJsonObjectNull setAll(final Iterable<JsonField> jsonFields) {
return this;
}
@Override
public boolean contains(final CharSequence key) {
return false;
}
@Override
public boolean containsFlatteningArrays(final CharSequence key) {
return false;
}
@Override
public ImmutableJsonObjectNull get(final JsonPointer pointer) {
return this;
}
@Override
public ImmutableJsonObjectNull get(final JsonFieldDefinition<?> fieldDefinition) {
return this;
}
@Override
public Optional<JsonValue> getValue(final CharSequence key) {
return Optional.empty();
}
@Override
public Optional<JsonValue> getValueFlatteningArrays(final CharSequence key) {
return Optional.empty();
}
@Override
public <T> Optional<T> getValue(final JsonFieldDefinition<T> fieldDefinition) {
return Optional.empty();
}
@Override
public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) {
throw JsonMissingFieldException.newBuilder().fieldName(fieldDefinition.getPointer()).build();
}
@Override
public ImmutableJsonObjectNull get(final JsonFieldSelector fieldSelector) {
return this;
}
@Override
public ImmutableJsonObjectNull remove(final CharSequence key) {
return this;
}
@Override
public List<JsonKey> getKeys() {
return Collections.emptyList();
}
@Override
public Optional<JsonField> getField(final CharSequence key) {
return Optional.empty();
}
@Override
public Iterator<JsonField> iterator() {
return Collections.emptyIterator();
}
@Override
public Stream<JsonField> stream() {
return Stream.empty();
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public int getSize() {
return 0;
}
@Override
public boolean equals(final Object obj) {
return obj instanceof JsonNull;
}
@Override
public int hashCode() {
return JsonNull.class.hashCode();
}
@Override
public String toString() {
return JsonFactory.nullLiteral().toString();
}
}