T
- the super type to switch over.public interface TypeSwitch<T>
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()));
Modifier and Type | Interface and Description |
---|---|
static class |
TypeSwitch.Default<T> |
static class |
TypeSwitch.Never |
Modifier and Type | Method and Description |
---|---|
<I extends T> |
is(@NotNull Class<I> type,
@NotNull Consumer<I> consumer)
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 type
T . |
@NotNull static <T> @NotNull TypeSwitch<T> never()
T
- the super type to switch over.@NotNull static <T> @NotNull TypeSwitch<T> when(@Nullable T t)
T
.T
- the super type to switch over.t
- the object of type T
.@NotNull <I extends T> @NotNull TypeSwitch<T> is(@NotNull @NotNull Class<I> type, @NotNull @NotNull Consumer<I> consumer)
If the type matches the returned TypeSwitch will not match any further type.
I
- the type to checktype
- the class of the type to check.consumer
- the callback to execute if the type matches.