查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at:
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package io.netty.handler.codec;
16  
17  import java.util.Collections;
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map.Entry;
21  import java.util.Set;
22  
23  import static io.netty.handler.codec.DefaultHeaders.HASH_CODE_SEED;
24  
25  public class EmptyHeaders<K, V, T extends Headers<K, V, T>> implements Headers<K, V, T> {
26      @Override
27      public V get(K name) {
28          return null;
29      }
30  
31      @Override
32      public V get(K name, V defaultValue) {
33          return defaultValue;
34      }
35  
36      @Override
37      public V getAndRemove(K name) {
38          return null;
39      }
40  
41      @Override
42      public V getAndRemove(K name, V defaultValue) {
43          return defaultValue;
44      }
45  
46      @Override
47      public List<V> getAll(K name) {
48          return Collections.emptyList();
49      }
50  
51      @Override
52      public List<V> getAllAndRemove(K name) {
53          return Collections.emptyList();
54      }
55  
56      @Override
57      public Boolean getBoolean(K name) {
58          return null;
59      }
60  
61      @Override
62      public boolean getBoolean(K name, boolean defaultValue) {
63          return defaultValue;
64      }
65  
66      @Override
67      public Byte getByte(K name) {
68          return null;
69      }
70  
71      @Override
72      public byte getByte(K name, byte defaultValue) {
73          return defaultValue;
74      }
75  
76      @Override
77      public Character getChar(K name) {
78          return null;
79      }
80  
81      @Override
82      public char getChar(K name, char defaultValue) {
83          return defaultValue;
84      }
85  
86      @Override
87      public Short getShort(K name) {
88          return null;
89      }
90  
91      @Override
92      public short getShort(K name, short defaultValue) {
93          return defaultValue;
94      }
95  
96      @Override
97      public Integer getInt(K name) {
98          return null;
99      }
100 
101     @Override
102     public int getInt(K name, int defaultValue) {
103         return defaultValue;
104     }
105 
106     @Override
107     public Long getLong(K name) {
108         return null;
109     }
110 
111     @Override
112     public long getLong(K name, long defaultValue) {
113         return defaultValue;
114     }
115 
116     @Override
117     public Float getFloat(K name) {
118         return null;
119     }
120 
121     @Override
122     public float getFloat(K name, float defaultValue) {
123         return defaultValue;
124     }
125 
126     @Override
127     public Double getDouble(K name) {
128         return null;
129     }
130 
131     @Override
132     public double getDouble(K name, double defaultValue) {
133         return defaultValue;
134     }
135 
136     @Override
137     public Long getTimeMillis(K name) {
138         return null;
139     }
140 
141     @Override
142     public long getTimeMillis(K name, long defaultValue) {
143         return defaultValue;
144     }
145 
146     @Override
147     public Boolean getBooleanAndRemove(K name) {
148         return null;
149     }
150 
151     @Override
152     public boolean getBooleanAndRemove(K name, boolean defaultValue) {
153         return defaultValue;
154     }
155 
156     @Override
157     public Byte getByteAndRemove(K name) {
158         return null;
159     }
160 
161     @Override
162     public byte getByteAndRemove(K name, byte defaultValue) {
163         return defaultValue;
164     }
165 
166     @Override
167     public Character getCharAndRemove(K name) {
168         return null;
169     }
170 
171     @Override
172     public char getCharAndRemove(K name, char defaultValue) {
173         return defaultValue;
174     }
175 
176     @Override
177     public Short getShortAndRemove(K name) {
178         return null;
179     }
180 
181     @Override
182     public short getShortAndRemove(K name, short defaultValue) {
183         return defaultValue;
184     }
185 
186     @Override
187     public Integer getIntAndRemove(K name) {
188         return null;
189     }
190 
191     @Override
192     public int getIntAndRemove(K name, int defaultValue) {
193         return defaultValue;
194     }
195 
196     @Override
197     public Long getLongAndRemove(K name) {
198         return null;
199     }
200 
201     @Override
202     public long getLongAndRemove(K name, long defaultValue) {
203         return defaultValue;
204     }
205 
206     @Override
207     public Float getFloatAndRemove(K name) {
208         return null;
209     }
210 
211     @Override
212     public float getFloatAndRemove(K name, float defaultValue) {
213         return defaultValue;
214     }
215 
216     @Override
217     public Double getDoubleAndRemove(K name) {
218         return null;
219     }
220 
221     @Override
222     public double getDoubleAndRemove(K name, double defaultValue) {
223         return defaultValue;
224     }
225 
226     @Override
227     public Long getTimeMillisAndRemove(K name) {
228         return null;
229     }
230 
231     @Override
232     public long getTimeMillisAndRemove(K name, long defaultValue) {
233         return defaultValue;
234     }
235 
236     @Override
237     public boolean contains(K name) {
238         return false;
239     }
240 
241     @Override
242     public boolean contains(K name, V value) {
243         return false;
244     }
245 
246     @Override
247     public boolean containsObject(K name, Object value) {
248         return false;
249     }
250 
251     @Override
252     public boolean containsBoolean(K name, boolean value) {
253         return false;
254     }
255 
256     @Override
257     public boolean containsByte(K name, byte value) {
258         return false;
259     }
260 
261     @Override
262     public boolean containsChar(K name, char value) {
263         return false;
264     }
265 
266     @Override
267     public boolean containsShort(K name, short value) {
268         return false;
269     }
270 
271     @Override
272     public boolean containsInt(K name, int value) {
273         return false;
274     }
275 
276     @Override
277     public boolean containsLong(K name, long value) {
278         return false;
279     }
280 
281     @Override
282     public boolean containsFloat(K name, float value) {
283         return false;
284     }
285 
286     @Override
287     public boolean containsDouble(K name, double value) {
288         return false;
289     }
290 
291     @Override
292     public boolean containsTimeMillis(K name, long value) {
293         return false;
294     }
295 
296     @Override
297     public int size() {
298         return 0;
299     }
300 
301     @Override
302     public boolean isEmpty() {
303         return true;
304     }
305 
306     @Override
307     public Set<K> names() {
308         return Collections.emptySet();
309     }
310 
311     @Override
312     public T add(K name, V value) {
313         throw new UnsupportedOperationException("read only");
314     }
315 
316     @Override
317     public T add(K name, Iterable<? extends V> values) {
318         throw new UnsupportedOperationException("read only");
319     }
320 
321     @Override
322     public T add(K name, V... values) {
323         throw new UnsupportedOperationException("read only");
324     }
325 
326     @Override
327     public T addObject(K name, Object value) {
328         throw new UnsupportedOperationException("read only");
329     }
330 
331     @Override
332     public T addObject(K name, Iterable<?> values) {
333         throw new UnsupportedOperationException("read only");
334     }
335 
336     @Override
337     public T addObject(K name, Object... values) {
338         throw new UnsupportedOperationException("read only");
339     }
340 
341     @Override
342     public T addBoolean(K name, boolean value) {
343         throw new UnsupportedOperationException("read only");
344     }
345 
346     @Override
347     public T addByte(K name, byte value) {
348         throw new UnsupportedOperationException("read only");
349     }
350 
351     @Override
352     public T addChar(K name, char value) {
353         throw new UnsupportedOperationException("read only");
354     }
355 
356     @Override
357     public T addShort(K name, short value) {
358         throw new UnsupportedOperationException("read only");
359     }
360 
361     @Override
362     public T addInt(K name, int value) {
363         throw new UnsupportedOperationException("read only");
364     }
365 
366     @Override
367     public T addLong(K name, long value) {
368         throw new UnsupportedOperationException("read only");
369     }
370 
371     @Override
372     public T addFloat(K name, float value) {
373         throw new UnsupportedOperationException("read only");
374     }
375 
376     @Override
377     public T addDouble(K name, double value) {
378         throw new UnsupportedOperationException("read only");
379     }
380 
381     @Override
382     public T addTimeMillis(K name, long value) {
383         throw new UnsupportedOperationException("read only");
384     }
385 
386     @Override
387     public T add(Headers<? extends K, ? extends V, ?> headers) {
388         throw new UnsupportedOperationException("read only");
389     }
390 
391     @Override
392     public T set(K name, V value) {
393         throw new UnsupportedOperationException("read only");
394     }
395 
396     @Override
397     public T set(K name, Iterable<? extends V> values) {
398         throw new UnsupportedOperationException("read only");
399     }
400 
401     @Override
402     public T set(K name, V... values) {
403         throw new UnsupportedOperationException("read only");
404     }
405 
406     @Override
407     public T setObject(K name, Object value) {
408         throw new UnsupportedOperationException("read only");
409     }
410 
411     @Override
412     public T setObject(K name, Iterable<?> values) {
413         throw new UnsupportedOperationException("read only");
414     }
415 
416     @Override
417     public T setObject(K name, Object... values) {
418         throw new UnsupportedOperationException("read only");
419     }
420 
421     @Override
422     public T setBoolean(K name, boolean value) {
423         throw new UnsupportedOperationException("read only");
424     }
425 
426     @Override
427     public T setByte(K name, byte value) {
428         throw new UnsupportedOperationException("read only");
429     }
430 
431     @Override
432     public T setChar(K name, char value) {
433         throw new UnsupportedOperationException("read only");
434     }
435 
436     @Override
437     public T setShort(K name, short value) {
438         throw new UnsupportedOperationException("read only");
439     }
440 
441     @Override
442     public T setInt(K name, int value) {
443         throw new UnsupportedOperationException("read only");
444     }
445 
446     @Override
447     public T setLong(K name, long value) {
448         throw new UnsupportedOperationException("read only");
449     }
450 
451     @Override
452     public T setFloat(K name, float value) {
453         throw new UnsupportedOperationException("read only");
454     }
455 
456     @Override
457     public T setDouble(K name, double value) {
458         throw new UnsupportedOperationException("read only");
459     }
460 
461     @Override
462     public T setTimeMillis(K name, long value) {
463         throw new UnsupportedOperationException("read only");
464     }
465 
466     @Override
467     public T set(Headers<? extends K, ? extends V, ?> headers) {
468         throw new UnsupportedOperationException("read only");
469     }
470 
471     @Override
472     public T setAll(Headers<? extends K, ? extends V, ?> headers) {
473         throw new UnsupportedOperationException("read only");
474     }
475 
476     @Override
477     public boolean remove(K name) {
478         return false;
479     }
480 
481     @Override
482     public T clear() {
483         return thisT();
484     }
485 
486     /**
487      * Equivalent to {@link #getAll(Object)} but no intermediate list is generated.
488      * @param name the name of the header to retrieve
489      * @return an {@link Iterator} of header values corresponding to {@code name}.
490      */
491     public Iterator<V> valueIterator(@SuppressWarnings("unused") K name) {
492         List<V> empty = Collections.emptyList();
493         return empty.iterator();
494     }
495 
496     @Override
497     public Iterator<Entry<K, V>> iterator() {
498         List<Entry<K, V>> empty = Collections.emptyList();
499         return empty.iterator();
500     }
501 
502     @Override
503     public boolean equals(Object o) {
504         if (!(o instanceof Headers)) {
505             return false;
506         }
507 
508         Headers<?, ?, ?> rhs = (Headers<?, ?, ?>) o;
509         return isEmpty() && rhs.isEmpty();
510     }
511 
512     @Override
513     public int hashCode() {
514         return HASH_CODE_SEED;
515     }
516 
517     @Override
518     public String toString() {
519         return new StringBuilder(getClass().getSimpleName()).append('[').append(']').toString();
520     }
521 
522     @SuppressWarnings("unchecked")
523     private T thisT() {
524         return (T) this;
525     }
526 }