Package com.hivemq.client.util
Interface TypeSwitch<T>
- Type Parameters:
T- the super type to switch over.
- All Known Implementing Classes:
TypeSwitch.Default,TypeSwitch.Never
public interface TypeSwitch<T>
Util to enable switching over types.
Example:
Mqtt5MessageException e;
TypeSwitch.when(e)
.is(Mqtt5ConnAckException.class, c -> System.out.println(c.getMqttMessage().getReasonCode()))
.is(Mqtt5DisconnectException.class, d -> System.out.println(d.getMqttMessage().getServerReference()));
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic class -
Method Summary
Modifier and TypeMethodDescription<I extends T>
@NotNull TypeSwitch<T> Checks if the object that is switched over is of a given type and if so executes a callback.static <T> @NotNull TypeSwitch<T> never()Returns a TypeSwitch object which does not match any type.static <T> @NotNull TypeSwitch<T> when(T t) Returns a TypeSwitch object for switching over an object of typeT.
-
Method Details
-
never
Returns a TypeSwitch object which does not match any type.- Type Parameters:
T- the super type to switch over.- Returns:
- the TypeSwitch object.
-
when
Returns a TypeSwitch object for switching over an object of typeT.- Type Parameters:
T- the super type to switch over.- Parameters:
t- the object of typeT.- Returns:
- the TypeSwitch object.
-
is
@NotNull <I extends T> @NotNull TypeSwitch<T> is(@NotNull @NotNull Class<I> type, @NotNull @NotNull Consumer<I> consumer) Checks if the object that is switched over is of a given type and if so executes a callback.If the type matches the returned TypeSwitch will not match any further type.
- Type Parameters:
I- the type to check- Parameters:
type- the class of the type to check.consumer- the callback to execute if the type matches.- Returns:
- the TypeSwitch object.
-