From 53505a49fd4df319f60b17beb09b5f1bad3a0e09 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Fri, 13 Mar 2020 11:17:39 +0100 Subject: [PATCH 1/2] Improved generics on add all methods --- .../mqtt/datatypes/MqttUserPropertiesImplBuilder.java | 4 ++-- .../mqtt/message/subscribe/MqttSubscribeBuilder.java | 6 ++++-- .../message/subscribe/mqtt3/Mqtt3SubscribeViewBuilder.java | 6 ++++-- .../mqtt/message/unsubscribe/MqttUnsubscribeBuilder.java | 4 ++-- .../unsubscribe/mqtt3/Mqtt3UnsubscribeViewBuilder.java | 4 ++-- .../mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java | 4 ++-- .../message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java | 4 ++-- .../mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java | 4 ++-- .../mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java | 4 ++-- .../message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java | 4 ++-- 10 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/hivemq/client/internal/mqtt/datatypes/MqttUserPropertiesImplBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/datatypes/MqttUserPropertiesImplBuilder.java index d6130b2a8..82a664d15 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/datatypes/MqttUserPropertiesImplBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/datatypes/MqttUserPropertiesImplBuilder.java @@ -73,14 +73,14 @@ public abstract class MqttUserPropertiesImplBuilder userProperties) { + public @NotNull B addAll(final @Nullable Collection<@Nullable ? extends Mqtt5UserProperty> userProperties) { Checks.notNull(userProperties, "User Properties"); listBuilder.ensureFree(userProperties.size()); userProperties.forEach(this::add); return self(); } - public @NotNull B addAll(final @Nullable Stream<@Nullable Mqtt5UserProperty> userProperties) { + public @NotNull B addAll(final @Nullable Stream<@Nullable ? extends Mqtt5UserProperty> userProperties) { Checks.notNull(userProperties, "User Properties"); userProperties.forEach(this::add); return self(); diff --git a/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/MqttSubscribeBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/MqttSubscribeBuilder.java index 354d06dd4..cce9d6ee9 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/MqttSubscribeBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/MqttSubscribeBuilder.java @@ -78,7 +78,9 @@ protected MqttSubscribeBuilder() { return self(); } - public @NotNull B addSubscriptions(final @Nullable Collection<@Nullable Mqtt5Subscription> subscriptions) { + public @NotNull B addSubscriptions( + final @Nullable Collection<@Nullable ? extends Mqtt5Subscription> subscriptions) { + Checks.notNull(subscriptions, "Subscriptions"); buildFirstSubscription(); subscriptionsBuilder.ensureFree(subscriptions.size()); @@ -87,7 +89,7 @@ protected MqttSubscribeBuilder() { return self(); } - public @NotNull B addSubscriptions(final @Nullable Stream<@Nullable Mqtt5Subscription> subscriptions) { + public @NotNull B addSubscriptions(final @Nullable Stream<@Nullable ? extends Mqtt5Subscription> subscriptions) { Checks.notNull(subscriptions, "Subscriptions"); buildFirstSubscription(); subscriptions.forEach(this::addSubscription); diff --git a/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilder.java index 48d266fd3..88ce3d19d 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/message/subscribe/mqtt3/Mqtt3SubscribeViewBuilder.java @@ -74,7 +74,9 @@ protected Mqtt3SubscribeViewBuilder() { return self(); } - public @NotNull B addSubscriptions(final @Nullable Collection<@Nullable Mqtt3Subscription> subscriptions) { + public @NotNull B addSubscriptions( + final @Nullable Collection<@Nullable ? extends Mqtt3Subscription> subscriptions) { + Checks.notNull(subscriptions, "Subscriptions"); buildFirstSubscription(); subscriptionsBuilder.ensureFree(subscriptions.size()); @@ -83,7 +85,7 @@ protected Mqtt3SubscribeViewBuilder() { return self(); } - public @NotNull B addSubscriptions(final @Nullable Stream<@Nullable Mqtt3Subscription> subscriptions) { + public @NotNull B addSubscriptions(final @Nullable Stream<@Nullable ? extends Mqtt3Subscription> subscriptions) { Checks.notNull(subscriptions, "Subscriptions"); buildFirstSubscription(); subscriptions.forEach(this::addSubscription); diff --git a/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/MqttUnsubscribeBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/MqttUnsubscribeBuilder.java index 3c7a444ef..76b598ff2 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/MqttUnsubscribeBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/MqttUnsubscribeBuilder.java @@ -80,7 +80,7 @@ public abstract class MqttUnsubscribeBuilder return self(); } - public @NotNull B addTopicFilters(final @Nullable Collection<@Nullable MqttTopicFilter> topicFilters) { + public @NotNull B addTopicFilters(final @Nullable Collection<@Nullable ? extends MqttTopicFilter> topicFilters) { Checks.notNull(topicFilters, "Topic Filters"); topicFiltersBuilder.ensureFree(topicFilters.size()); topicFilters.forEach(this::addTopicFilter); @@ -88,7 +88,7 @@ public abstract class MqttUnsubscribeBuilder return self(); } - public @NotNull B addTopicFilters(final @Nullable Stream<@Nullable MqttTopicFilter> topicFilters) { + public @NotNull B addTopicFilters(final @Nullable Stream<@Nullable ? extends MqttTopicFilter> topicFilters) { Checks.notNull(topicFilters, "Topic Filters"); topicFilters.forEach(this::addTopicFilter); ensureAtLeastOneSubscription(); diff --git a/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/mqtt3/Mqtt3UnsubscribeViewBuilder.java b/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/mqtt3/Mqtt3UnsubscribeViewBuilder.java index 7c4ca05d2..f131a5ed2 100644 --- a/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/mqtt3/Mqtt3UnsubscribeViewBuilder.java +++ b/src/main/java/com/hivemq/client/internal/mqtt/message/unsubscribe/mqtt3/Mqtt3UnsubscribeViewBuilder.java @@ -77,7 +77,7 @@ public abstract class Mqtt3UnsubscribeViewBuilder topicFilters) { + public @NotNull B addTopicFilters(final @Nullable Collection<@Nullable ? extends MqttTopicFilter> topicFilters) { Checks.notNull(topicFilters, "Topic Filters"); topicFiltersBuilder.ensureFree(topicFilters.size()); topicFilters.forEach(this::addTopicFilter); @@ -85,7 +85,7 @@ public abstract class Mqtt3UnsubscribeViewBuilder topicFilters) { + public @NotNull B addTopicFilters(final @Nullable Stream<@Nullable ? extends MqttTopicFilter> topicFilters) { Checks.notNull(topicFilters, "Topic Filters"); topicFilters.forEach(this::addTopicFilter); ensureAtLeastOneSubscription(); diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java index 1352f7e83..4161d14e2 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java @@ -75,7 +75,7 @@ public interface Mqtt3SubscribeBuilderBase subscriptions); + @NotNull C addSubscriptions(@NotNull Collection<@NotNull ? extends Mqtt3Subscription> subscriptions); /** * Adds a stream of {@link Mqtt3Subscription}s to the {@link Mqtt3Subscribe#getSubscriptions() list of @@ -85,7 +85,7 @@ public interface Mqtt3SubscribeBuilderBase subscriptions); + @NotNull C addSubscriptions(@NotNull Stream<@NotNull ? extends Mqtt3Subscription> subscriptions); /** * {@link Mqtt3SubscribeBuilderBase} that provides additional methods for the first subscription. diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java index 7b5c444e3..e95b7677e 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java @@ -88,7 +88,7 @@ public interface Mqtt3UnsubscribeBuilderBase topicFilters); + @NotNull C addTopicFilters(@NotNull Collection<@NotNull ? extends MqttTopicFilter> topicFilters); /** * Adds a stream of {@link MqttTopicFilter Topic Filters} to the {@link Mqtt3Unsubscribe#getTopicFilters() list of @@ -98,7 +98,7 @@ public interface Mqtt3UnsubscribeBuilderBase topicFilters); + @NotNull C addTopicFilters(@NotNull Stream<@NotNull ? extends MqttTopicFilter> topicFilters); /** * Reverses the subscriptions of a Subscribe message by adding their Topic Filters. diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java index 64c885a2b..3bcae2367 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java @@ -80,7 +80,7 @@ public interface Mqtt5UserPropertiesBuilderBase userProperties); + @NotNull B addAll(@NotNull Collection<@NotNull ? extends Mqtt5UserProperty> userProperties); /** * Adds a stream of {@link Mqtt5UserProperty User Properties}. @@ -89,5 +89,5 @@ public interface Mqtt5UserPropertiesBuilderBase userProperties); + @NotNull B addAll(@NotNull Stream<@NotNull ? extends Mqtt5UserProperty> userProperties); } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java index 143a402dc..07d9c0b50 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java @@ -77,7 +77,7 @@ public interface Mqtt5SubscribeBuilderBase subscriptions); + @NotNull C addSubscriptions(@NotNull Collection<@NotNull ? extends Mqtt5Subscription> subscriptions); /** * Adds a stream of {@link Mqtt5Subscription}s to the {@link Mqtt5Subscribe#getSubscriptions() list of @@ -87,7 +87,7 @@ public interface Mqtt5SubscribeBuilderBase subscriptions); + @NotNull C addSubscriptions(@NotNull Stream<@NotNull ? extends Mqtt5Subscription> subscriptions); /** * {@link Mqtt5SubscribeBuilderBase} that is complete which means all mandatory fields are set. diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java index b844cf468..55fa10291 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java @@ -90,7 +90,7 @@ public interface Mqtt5UnsubscribeBuilderBase topicFilters); + @NotNull C addTopicFilters(@NotNull Collection<@NotNull ? extends MqttTopicFilter> topicFilters); /** * Adds a stream of {@link MqttTopicFilter Topic Filters} to the {@link Mqtt5Unsubscribe#getTopicFilters() list of @@ -100,7 +100,7 @@ public interface Mqtt5UnsubscribeBuilderBase topicFilters); + @NotNull C addTopicFilters(@NotNull Stream<@NotNull ? extends MqttTopicFilter> topicFilters); /** * Reverses the subscriptions of a Subscribe message by adding their Topic Filters. From 6f690dea74517a6b320206b7939d02de53fe3bc2 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Fri, 13 Mar 2020 11:18:36 +0100 Subject: [PATCH 2/2] Added missing CheckReturnValue annotations --- .../com/hivemq/client/mqtt/MqttWebSocketConfigBuilderBase.java | 1 + .../mqtt3/message/subscribe/Mqtt3SubscribeBuilderBase.java | 3 +++ .../mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java | 3 +++ .../mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java | 3 +++ .../mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java | 3 +++ .../mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java | 3 +++ 6 files changed, 16 insertions(+) diff --git a/src/main/java/com/hivemq/client/mqtt/MqttWebSocketConfigBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/MqttWebSocketConfigBuilderBase.java index b42c93962..f21146c4f 100644 --- a/src/main/java/com/hivemq/client/mqtt/MqttWebSocketConfigBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/MqttWebSocketConfigBuilderBase.java @@ -46,6 +46,7 @@ public interface MqttWebSocketConfigBuilderBase subscriptions); /** @@ -85,6 +87,7 @@ public interface Mqtt3SubscribeBuilderBase subscriptions); /** diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java index e95b7677e..2dfa8abdf 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt3/message/unsubscribe/Mqtt3UnsubscribeBuilderBase.java @@ -78,6 +78,7 @@ public interface Mqtt3UnsubscribeBuilderBase topicFilters); /** @@ -98,6 +100,7 @@ public interface Mqtt3UnsubscribeBuilderBase topicFilters); /** diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java index 3bcae2367..512f3443f 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/datatypes/Mqtt5UserPropertiesBuilderBase.java @@ -71,6 +71,7 @@ public interface Mqtt5UserPropertiesBuilderBase userProperties); /** @@ -89,5 +91,6 @@ public interface Mqtt5UserPropertiesBuilderBase userProperties); } diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java index 07d9c0b50..1a8b98f08 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/subscribe/Mqtt5SubscribeBuilderBase.java @@ -67,6 +67,7 @@ public interface Mqtt5SubscribeBuilderBase subscriptions); /** @@ -87,6 +89,7 @@ public interface Mqtt5SubscribeBuilderBase subscriptions); /** diff --git a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java index 55fa10291..a25e760f4 100644 --- a/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java +++ b/src/main/java/com/hivemq/client/mqtt/mqtt5/message/unsubscribe/Mqtt5UnsubscribeBuilderBase.java @@ -80,6 +80,7 @@ public interface Mqtt5UnsubscribeBuilderBase topicFilters); /** @@ -100,6 +102,7 @@ public interface Mqtt5UnsubscribeBuilderBase topicFilters); /**