In
- Input type.Out
- Output type.public class Switch<In,Out> extends Object
String var = ...; Out out = Switch.newSwitch(var) .when("A", () -> doA()) .when("B", () -> doB()) .value();
Modifier and Type | Method and Description |
---|---|
static <In,Out> Switch<In,Out> |
newSwitch(In value)
Creates a new switch.
|
static <Out> Switch<String,Out> |
newSwitch(String value)
Creates a new string switch.
|
Optional<Out> |
value()
Test all the switches and find the first who best matches the input value.
|
Switch<In,Out> |
when(In value,
ExSupplier<Out> fn)
Append a new option.
|
Switch<In,Out> |
when(In value,
Out result)
Append a new option.
|
Switch<In,Out> |
when(Predicate<In> predicate,
ExSupplier<Out> fn)
Append a new option.
|
Switch<In,Out> |
when(Predicate<In> predicate,
Out result)
Append a new option.
|
public Switch<In,Out> when(In value, Out result)
value
- A value to test.result
- A constant value.public Switch<In,Out> when(Predicate<In> predicate, Out result)
predicate
- A predicate to test.result
- A constant value.public Switch<In,Out> when(In value, ExSupplier<Out> fn)
value
- A value to test.fn
- A result supplier value.public Switch<In,Out> when(Predicate<In> predicate, ExSupplier<Out> fn)
predicate
- A predicate to test.fn
- A result supplier value.public Optional<Out> value() throws Exception
Exception
- If something goes wrong.public static <In,Out> Switch<In,Out> newSwitch(In value)
In
- Input value.Out
- Output value.value
- An input value.Copyright © 2015. All rights reserved.