public abstract class Choices<I> extends Object
<I>.
When evaluating a specific input, a single choice is represented
as an int value, which can be used as a decision criterion in, for example, a switch statement.
To get an instance, use either serial(Predicate[]), serial(Collection),
parallel(Predicate[]) or parallel(Collection).
| Constructor and Description |
|---|
Choices() |
| Modifier and Type | Method and Description |
|---|---|
<R> Function<I,R> |
andThen(IntFunction<? extends R> function)
|
abstract int |
apply(I input)
Returns an
int value representing the combined results of the associated
boolean criteria. |
<R> Function<I,R> |
applying(Collection<? extends Function<? super I,? extends R>> methods)
Returns a
Function that maps an input of type <I> to one of the given methods
to finally get a result of type <R>. |
<R> Function<I,R> |
applying(Function<? super I,? extends R>... methods)
Returns a
Function that maps an input of type <I> to one of the given methods
to finally get a result of type <R>. |
static <I> Choices<I> |
parallel(Collection<? extends Predicate<? super I>> criteria)
Retrieves a new instance consisting of a combination of boolean criteria.
|
static <I> Choices<I> |
parallel(Predicate<I>... criteria)
Retrieves a new instance consisting of a combination of boolean criteria.
|
<R> Function<I,R> |
replying(Collection<? extends R> results)
|
<R> Function<I,R> |
replying(R... results)
|
static <I> Choices<I> |
serial(Collection<? extends Predicate<? super I>> criteria)
Retrieves a new instance consisting of a series of boolean criteria.
|
static <I> Choices<I> |
serial(Predicate<I>... criteria)
Retrieves a new instance consisting of a series of boolean criteria.
|
@SafeVarargs public static <I> Choices<I> serial(Predicate<I>... criteria)
When evaluating a specific input, the criteria will be
evaluated just like in a series of if-else-statements ...
final int n = criteria.length;
if (criteria[0].test(input)) {
return 0;
} else if (criteria[1].test(input)) {
return 1;
} else if (criteria[2].test(input)) {
return 2;
} [...]
else if (criteria[n-1].test(input)) {
return n-1;
} else {
return n;
}
Let n be the number of given criteria, then n+1 is the number of possible results when evaluating an input. More precisely, the result range is between 0 and n (inclusive).
public static <I> Choices<I> serial(Collection<? extends Predicate<? super I>> criteria)
See serial(Predicate[]) for more details.
criteria - CAUTION: be careful with Collections other than Lists:
The effective number and order of elements will be significant!@SafeVarargs public static <I> Choices<I> parallel(Predicate<I>... criteria)
When evaluating a specific input, all criteria are always
evaluated and each represented by a specific bit (MSB first)
of the resulting int, in principle as in the following case of three criteria ...
if (criteria[0].test(input)) {
if (criteria[1].test(input)) {
if (criteria[2].test(input)) {
return 0b111;
} else {
return 0b110;
}
} else {
if (criteria[2].test(input)) {
return 0b101;
} else {
return 0b100;
}
}
} else {
if (criteria[1].test(input)) {
if (criteria[2].test(input)) {
return 0b011;
} else {
return 0b010;
}
} else {
if (criteria[2].test(input)) {
return 0b001;
} else {
return 0b000;
}
}
}
Let n be the number of given criteria, then 2n is the number of possible results when evaluating an input. More precisely, the result range is between 0 and 2n-1 (inclusive).
public static <I> Choices<I> parallel(Collection<? extends Predicate<? super I>> criteria)
See parallel(Predicate[]) for more details.
criteria - CAUTION: be careful with Collections other than Lists:
The effective number and order of elements will be significant!public abstract int apply(I input)
int value representing the combined results of the associated
boolean criteria.
The kind of combination and the result range depends on how this Choices were created.
public final <R> Function<I,R> andThen(IntFunction<? extends R> function)
@SafeVarargs public final <R> Function<I,R> replying(R... results)
Function that maps an input of type <I> to one of the given results
of type <R>.
The number of results should equal the number of possible results when
evaluating an input. The latter depends on how this
Choices were created.
public final <R> Function<I,R> replying(Collection<? extends R> results)
Function that maps an input of type <I> to one of the given results
of type <R>.
The number of results should equal the number of possible results when
evaluating an input. The latter depends on how this
Choices were created.
results - CAUTION: be careful with Collections other than Lists:
The effective number and order of elements will be significant!serial(Predicate[]),
serial(Collection),
parallel(Predicate[]),
parallel(Collection)@SafeVarargs public final <R> Function<I,R> applying(Function<? super I,? extends R>... methods)
Function that maps an input of type <I> to one of the given methods
to finally get a result of type <R>.
The number of results should equal the number of possible results when
evaluating an input. The latter depends on how this
Choices were created.
public final <R> Function<I,R> applying(Collection<? extends Function<? super I,? extends R>> methods)
Function that maps an input of type <I> to one of the given methods
to finally get a result of type <R>.
The number of methods should equal the number of possible results when
evaluating an input. The latter depends on how this
Choices were created.
methods - CAUTION: be careful with Collections other than Lists:
The effective number and order of elements will be significant!serial(Predicate[]),
serial(Collection),
parallel(Predicate[]),
parallel(Collection)Copyright © 2026 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.