View Javadoc
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    * http://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.Comparator;
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Map.Entry;
22  import java.util.Set;
23  
24  /**
25   * Extension to the {@link Headers} interface to provide methods which convert the
26   * native {@code UnconvertedType} to the not-native {@code ConvertedType}
27   */
28  public interface ConvertibleHeaders<UnconvertedType, ConvertedType> extends Headers<UnconvertedType> {
29  
30      /**
31       * Interface to do conversions to and from the two generic type parameters
32       */
33      interface TypeConverter<UnconvertedType, ConvertedType> {
34          /**
35           * Convert a native value
36           * @param value The value to be converted
37           * @return The conversion results
38           */
39          ConvertedType toConvertedType(UnconvertedType value);
40  
41          /**
42           * Undo a conversion and restore the original native type
43           * @param value The converted value
44           * @return The original native type
45           */
46          UnconvertedType toUnconvertedType(ConvertedType value);
47      }
48  
49      /**
50       * Invokes {@link Headers#get(Object)} and does a conversion on the results if not {@code null}
51       * @param name The name of entry to get
52       * @return The value corresponding to {@code name} and then converted
53       */
54      ConvertedType getAndConvert(UnconvertedType name);
55  
56      /**
57       * Invokes {@link Headers#get(Object, Object)} and does a conversion on the results if not {@code null}
58       * @param name The name of entry to get
59       * @return The value corresponding to {@code name} and then converted
60       */
61      ConvertedType getAndConvert(UnconvertedType name, ConvertedType defaultValue);
62  
63      /**
64       * Invokes {@link Headers#getAndRemove(Object)} and does a conversion on the results if not {@code null}
65       * @param name The name of entry to get
66       * @return The value corresponding to {@code name} and then converted
67       */
68      ConvertedType getAndRemoveAndConvert(UnconvertedType name);
69  
70      /**
71       * Invokes {@link Headers#getAndRemove(Object, Object)} and does
72       * a conversion on the results if not {@code null}
73       * @param name The name of entry to get
74       * @return The value corresponding to {@code name} and then converted
75       */
76      ConvertedType getAndRemoveAndConvert(UnconvertedType name, ConvertedType defaultValue);
77  
78      /**
79       * Invokes {@link Headers#getAll(Object)} and does a conversion on the results if not {@code null}
80       * @param name The name of entry to get
81       * @return The values corresponding to {@code name} and then converted
82       */
83      List<ConvertedType> getAllAndConvert(UnconvertedType name);
84  
85      /**
86       * Invokes {@link Headers#getAllAndRemove(Object)} and does a conversion on the results if not {@code null}
87       * @param name The name of entry to get
88       * @return The values corresponding to {@code name} and then converted
89       */
90      List<ConvertedType> getAllAndRemoveAndConvert(UnconvertedType name);
91  
92      /**
93       * Invokes {@link Headers#entries()} and lazily does a conversion on the results as they are accessed
94       *
95       * @return The values corresponding to {@code name} and then lazily converted
96       */
97      List<Map.Entry<ConvertedType, ConvertedType>> entriesConverted();
98  
99      /**
100      * Invokes {@link Headers#iterator()} and lazily does a conversion on the results as they are accessed
101      *
102      * @return Iterator which will provide converted values corresponding to {@code name}
103      */
104     Iterator<Entry<ConvertedType, ConvertedType>> iteratorConverted();
105 
106     /**
107      * Invokes {@link Headers#names()} and does a conversion on the results
108      *
109      * @return The values corresponding to {@code name} and then converted
110      */
111     Set<ConvertedType> namesAndConvert(Comparator<ConvertedType> comparator);
112 }