2121import java .text .MessageFormat ;
2222import java .util .ArrayList ;
2323import java .util .Arrays ;
24+ import java .util .Collections ;
2425import java .util .HashMap ;
2526import java .util .List ;
2627import java .util .Map ;
4142 * Base for Kafka header mappers.
4243 *
4344 * @author Gary Russell
45+ * @author Artem Bilan
46+ *
4447 * @since 2.1.3
4548 *
4649 */
@@ -50,7 +53,7 @@ public abstract class AbstractKafkaHeaderMapper implements KafkaHeaderMapper {
5053
5154 private final List <HeaderMatcher > matchers = new ArrayList <>();
5255
53- private final Map <String , Boolean > rawMappedtHeaders = new HashMap <>();
56+ private final Map <String , Boolean > rawMappedHeaders = new HashMap <>();
5457
5558 private boolean mapAllStringsOut ;
5659
@@ -88,17 +91,15 @@ public AbstractKafkaHeaderMapper(String... patterns) {
8891 protected final void addMatchers (HeaderMatcher ... matchersToAdd ) {
8992 Assert .notNull (matchersToAdd , "'matchersToAdd' cannot be null" );
9093 Assert .noNullElements (matchersToAdd , "'matchersToAdd' cannot have null elements" );
91- for (HeaderMatcher matcher : matchersToAdd ) {
92- this .matchers .add (matcher );
93- }
94+ Collections .addAll (this .matchers , matchersToAdd );
9495 }
9596
9697 /**
9798 * Set to true to map all {@code String} valued outbound headers to {@code byte[]}.
9899 * To map to a {@code String} for inbound, there must be an entry in the rawMappedHeaders map.
99100 * @param mapAllStringsOut true to map all strings.
100101 * @since 2.2.5
101- * @see #setRawMappedHaeaders (Map)
102+ * @see #setRawMappedHeaders (Map)
102103 */
103104 public void setMapAllStringsOut (boolean mapAllStringsOut ) {
104105 this .mapAllStringsOut = mapAllStringsOut ;
@@ -112,7 +113,7 @@ protected Charset getCharset() {
112113 * Set the charset to use when mapping String-valued headers to/from byte[]. Default UTF-8.
113114 * @param charset the charset.
114115 * @since 2.2.5
115- * @see #setRawMappedHaeaders (Map)
116+ * @see #setRawMappedHeaders (Map)
116117 */
117118 public void setCharset (Charset charset ) {
118119 Assert .notNull (charset , "'charset' cannot be null" );
@@ -129,10 +130,10 @@ public void setCharset(Charset charset) {
129130 * @see #setCharset(Charset)
130131 * @see #setMapAllStringsOut(boolean)
131132 */
132- public void setRawMappedHaeaders (Map <String , Boolean > rawMappedHeaders ) {
133+ public void setRawMappedHeaders (Map <String , Boolean > rawMappedHeaders ) {
133134 if (!ObjectUtils .isEmpty (rawMappedHeaders )) {
134- this .rawMappedtHeaders .clear ();
135- this .rawMappedtHeaders .putAll (rawMappedHeaders );
135+ this .rawMappedHeaders .clear ();
136+ this .rawMappedHeaders .putAll (rawMappedHeaders );
136137 }
137138 }
138139
@@ -167,7 +168,7 @@ protected boolean matches(String header) {
167168 /**
168169 * Check if the value is a String and convert to byte[], if so configured.
169170 * @param key the header name.
170- * @param value the headet value.
171+ * @param value the header value.
171172 * @return the value to add.
172173 * @since 2.2.5
173174 */
@@ -181,7 +182,7 @@ protected Object headerValueToAddOut(String key, Object value) {
181182
182183 @ Nullable
183184 private byte [] mapRawOut (String header , Object value ) {
184- if (this .mapAllStringsOut || this .rawMappedtHeaders .containsKey (header )) {
185+ if (this .mapAllStringsOut || this .rawMappedHeaders .containsKey (header )) {
185186 if (value instanceof byte []) {
186187 return (byte []) value ;
187188 }
@@ -197,7 +198,7 @@ else if (value instanceof String) {
197198 * @param header the header.
198199 * @return the value to add.
199200 */
200- protected Object headertValueToAddIn (Header header ) {
201+ protected Object headerValueToAddIn (Header header ) {
201202 Object mapped = mapRawIn (header .key (), header .value ());
202203 if (mapped == null ) {
203204 mapped = header .value ();
@@ -207,7 +208,7 @@ protected Object headertValueToAddIn(Header header) {
207208
208209 @ Nullable
209210 private String mapRawIn (String header , byte [] value ) {
210- Boolean asString = this .rawMappedtHeaders .get (header );
211+ Boolean asString = this .rawMappedHeaders .get (header );
211212 if (Boolean .TRUE .equals (asString )) {
212213 return new String (value , this .charset );
213214 }
@@ -275,7 +276,7 @@ protected static class SimplePatternBasedHeaderMatcher implements HeaderMatcher
275276
276277 private final boolean negate ;
277278
278- public SimplePatternBasedHeaderMatcher (String pattern ) {
279+ protected SimplePatternBasedHeaderMatcher (String pattern ) {
279280 this (pattern .startsWith ("!" ) ? pattern .substring (1 ) : pattern , pattern .startsWith ("!" ));
280281 }
281282
0 commit comments