Skip to content

Commit 1a6a51c

Browse files
fussel178pklaschka
andcommitted
feat(api)!: Make HeaderInformation MultiMap complete and rename method get to getString.
BREAKING-CHANGE: Rename method `get` to `getString` in `HeaderInformation` class. Co-authored-by: pklaschka <[email protected]>
1 parent 80cb961 commit 1a6a51c

File tree

3 files changed

+103
-178
lines changed

3 files changed

+103
-178
lines changed

telestion-api/src/main/java/de/wuespace/telestion/api/message/HeaderInformation.java

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @author Cedric Boes (@cb0s), Ludwig Richter (@fussel178)
4949
* @see de.wuespace.telestion.api.verticle.trait.WithEventBus
5050
*/
51-
public class HeaderInformation {
51+
public class HeaderInformation implements MultiMap {
5252

5353
///////////////////////////////////////////////////////////////////////////
5454
// utilities
@@ -201,6 +201,16 @@ public DeliveryOptions toOptions() {
201201
// getters
202202
///////////////////////////////////////////////////////////////////////////
203203

204+
@Override
205+
public String get(CharSequence name) {
206+
return headers.get(name);
207+
}
208+
209+
@Override
210+
public String get(String name) {
211+
return headers.get(name);
212+
}
213+
204214
/**
205215
* Returns the first stored value assigned to the key as {@link String}.
206216
* If no value is assigned to the key, an {@link Optional#empty() empty Optional} is returned instead.
@@ -209,7 +219,7 @@ public DeliveryOptions toOptions() {
209219
* @return the first stored value wrapped inside an {@link Optional} for better {@code null} type safety
210220
* @see MultiMap#get(String)
211221
*/
212-
public Optional<String> get(String key) {
222+
public Optional<String> getString(String key) {
213223
return Optional.ofNullable(headers.get(key));
214224
}
215225

@@ -222,8 +232,8 @@ public Optional<String> get(String key) {
222232
* @return the first stored value or the default value if no value is assigned to the key
223233
* @see MultiMap#get(String)
224234
*/
225-
public String get(String key, String defaultValue) {
226-
return get(key).orElse(defaultValue);
235+
public String getString(String key, String defaultValue) {
236+
return getString(key).orElse(defaultValue);
227237
}
228238

229239
/**
@@ -235,7 +245,7 @@ public String get(String key, String defaultValue) {
235245
* @see MultiMap#get(String)
236246
*/
237247
public Optional<Byte> getByte(String key) {
238-
return get(key).map(safeParse(Byte::parseByte));
248+
return getString(key).map(safeParse(Byte::parseByte));
239249
}
240250

241251
/**
@@ -260,7 +270,7 @@ public byte getByte(String key, byte defaultValue) {
260270
* @see MultiMap#get(String)
261271
*/
262272
public Optional<Integer> getInt(String key) {
263-
return get(key).map(safeParse(Integer::parseInt));
273+
return getString(key).map(safeParse(Integer::parseInt));
264274
}
265275

266276
/**
@@ -285,7 +295,7 @@ public int getInt(String key, int defaultValue) {
285295
* @see MultiMap#get(String)
286296
*/
287297
public Optional<Long> getLong(String key) {
288-
return get(key).map(safeParse(Long::parseLong));
298+
return getString(key).map(safeParse(Long::parseLong));
289299
}
290300

291301
/**
@@ -310,7 +320,7 @@ public long getLong(String key, long defaultValue) {
310320
* @see MultiMap#get(String)
311321
*/
312322
public Optional<Float> getFloat(String key) {
313-
return get(key).map(safeParse(Float::parseFloat));
323+
return getString(key).map(safeParse(Float::parseFloat));
314324
}
315325

316326
/**
@@ -335,7 +345,7 @@ public float getFloat(String key, float defaultValue) {
335345
* @see MultiMap#get(String)
336346
*/
337347
public Optional<Double> getDouble(String key) {
338-
return get(key).map(safeParse(Double::parseDouble));
348+
return getString(key).map(safeParse(Double::parseDouble));
339349
}
340350

341351
/**
@@ -360,7 +370,7 @@ public double getDouble(String key, double defaultValue) {
360370
* @see MultiMap#get(String)
361371
*/
362372
public Optional<Character> getChar(String key) {
363-
return get(key).map(value -> value.length() == 1 ? value.charAt(0) : null);
373+
return getString(key).map(value -> value.length() == 1 ? value.charAt(0) : null);
364374
}
365375

366376
/**
@@ -385,7 +395,7 @@ public char getChar(String key, char defaultValue) {
385395
* @see MultiMap#get(String)
386396
*/
387397
public Optional<Boolean> getBoolean(String key) {
388-
return get(key).map(Boolean::parseBoolean);
398+
return getString(key).map(Boolean::parseBoolean);
389399
}
390400

391401
/**
@@ -412,6 +422,11 @@ public List<String> getAll(String key) {
412422
return headers.getAll(key);
413423
}
414424

425+
@Override
426+
public List<String> getAll(CharSequence name) {
427+
return headers.getAll(name);
428+
}
429+
415430
///////////////////////////////////////////////////////////////////////////
416431
// adders
417432
///////////////////////////////////////////////////////////////////////////
@@ -548,6 +563,26 @@ public HeaderInformation addAll(Map<String, String> headers) {
548563
return this;
549564
}
550565

566+
@Override
567+
public MultiMap set(String name, String value) {
568+
return headers.set(name, value);
569+
}
570+
571+
@Override
572+
public MultiMap set(CharSequence name, CharSequence value) {
573+
return headers.set(name, value);
574+
}
575+
576+
@Override
577+
public MultiMap set(String name, Iterable<String> values) {
578+
return headers.set(name, values);
579+
}
580+
581+
@Override
582+
public MultiMap set(CharSequence name, Iterable<CharSequence> values) {
583+
return headers.set(name, values);
584+
}
585+
551586
/**
552587
* Appends all values assigned to their keys from the {@link HeaderInformation} object to already existing values.
553588
* Returns a reference to {@code this} for fluent design.
@@ -728,6 +763,11 @@ public boolean contains(String key) {
728763
return headers.contains(key);
729764
}
730765

766+
@Override
767+
public boolean contains(CharSequence name) {
768+
return headers.contains(name);
769+
}
770+
731771
/**
732772
* Removes all values assigned to the key.
733773
* Returns a reference to {@code this} for fluent design.
@@ -741,6 +781,11 @@ public HeaderInformation remove(String key) {
741781
return this;
742782
}
743783

784+
@Override
785+
public MultiMap remove(CharSequence name) {
786+
return headers.remove(name);
787+
}
788+
744789
/**
745790
* Clears all values assigned to their keys.
746791
* Returns a reference to {@code this} for fluent design.
@@ -773,6 +818,26 @@ public Set<String> names() {
773818
return headers.names();
774819
}
775820

821+
@Override
822+
public MultiMap add(String name, String value) {
823+
return headers.add(name, value);
824+
}
825+
826+
@Override
827+
public MultiMap add(CharSequence name, CharSequence value) {
828+
return headers.add(name, value);
829+
}
830+
831+
@Override
832+
public MultiMap add(String name, Iterable<String> values) {
833+
return headers.add(name, values);
834+
}
835+
836+
@Override
837+
public MultiMap add(CharSequence name, Iterable<CharSequence> values) {
838+
return headers.add(name, values);
839+
}
840+
776841
/**
777842
* Returns {@code true}, if the wrapped {@link MultiMap Vert.x headers} have no entries.
778843
*
@@ -877,4 +942,9 @@ private static <T, R> Function<T, R> safeParse(Function<T, R> func) {
877942
}
878943

879944
private static final Logger logger = LoggerFactory.getLogger(HeaderInformation.class);
945+
946+
@Override
947+
public Iterator<Map.Entry<String, String>> iterator() {
948+
return headers.iterator();
949+
}
880950
}

telestion-api/src/main/java/de/wuespace/telestion/api/message/MultiMapUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616
public class MultiMapUtils {
1717

1818
/**
19-
* Merges an array of multi-maps into one multi-map
19+
* Merges an array of multi-maps into one multimap
2020
* with the {@link MultiMap#addAll(MultiMap) addAll} function.
2121
*
2222
* @param maps multi-maps that you want to merge
23-
* @return a new multi-map with the merged content of the other multi-maps
23+
* @return a new multimap with the merged content of the other multi-maps
2424
*/
2525
public static MultiMap merge(MultiMap... maps) {
2626
return merge(Arrays.stream(maps));
2727
}
2828

2929
/**
30-
* Merges a list of multi-maps into one multi-map
30+
* Merges a list of multi-maps into one multimap
3131
* with the {@link MultiMap#addAll(MultiMap) addAll} function.
3232
*
3333
* @param list multi-maps that you want to merge
34-
* @return a new multi-map with the merged content of the other multi-maps
34+
* @return a new multimap with the merged content of the other multi-maps
3535
*/
3636
public static MultiMap merge(List<MultiMap> list) {
3737
return merge(list.stream());
3838
}
3939

4040
/**
41-
* Merges a stream of multi-maps into one multi-map
41+
* Merges a stream of multi-maps into one multimap
4242
* with the {@link MultiMap#addAll(MultiMap) addAll} function.
4343
*
4444
* @param stream a stream that contains the multi-maps that you want to merge
45-
* @return a new multi-map with the merged content of the other multi-maps
45+
* @return a new multimap with the merged content of the other multi-maps
4646
*/
4747
public static MultiMap merge(Stream<MultiMap> stream) {
4848
var finalMap = MultiMap.caseInsensitiveMultiMap();

0 commit comments

Comments
 (0)