public class Matchables
extends java.lang.Object
Constructor and Description |
---|
Matchables() |
Modifier and Type | Method and Description |
---|---|
static <T> Xor<Queue<T>,Topic<T>> |
adapter(Adapter<T> adapter)
Create a Pattern Matcher on cyclops2-react adapter type (note this will only match
on known types within the cyclops2-react library)
|
static <W extends WitnessType<W>,T> |
anyM(AnyM<W,T> anyM)
Pattern Match on a FutureW handling success and failure cases differently
|
static <T> Xor<java.util.concurrent.BlockingQueue<T>,java.util.Queue<T>> |
blocking(java.util.Queue<T> queue)
Pattern matching on the blocking / non-blocking nature of a Queue
|
public static <T> Xor<Queue<T>,Topic<T>> adapter(Adapter<T> adapter)
Adapter<Integer> adapter = QueueFactories.<Integer>unboundedQueue()
.build();
String result = Matchables.adapter(adapter)
.visit(queue->"we have a queue",topic->"we have a topic");
//"we have a queue"
adapter
- Adapter to match onpublic static <W extends WitnessType<W>,T> Xor<AnyMValue<W,T>,AnyMSeq<W,T>> anyM(AnyM<W,T> anyM)
Eval<Integer> result = Matchables.future(FutureW.ofResult(1))
.matches(c-> c.is( when(some(1)), transform(10)),
c->c.is(when(instanceOf(RuntimeException.class)), transform(2)),
otherwise(3));
//Eval.now[10]
Eval<Integer> result = Matchables.future(FutureW.ofError(new RuntimeException()))
.matches(c-> c.is( when(some(10)), transform(2)),
c->c.is(when(instanceOf(RuntimeException.class)), transform(2)),
otherwise(3));
//Eval.now(2)
future
- Future to match onpublic static <T> Xor<java.util.concurrent.BlockingQueue<T>,java.util.Queue<T>> blocking(java.util.Queue<T> queue)
Matchables.blocking(new ManyToManyConcurrentArrayQueue(10))
.visit(c->"blocking", c->"not")
//"not"
Matchables.blocking(new LinkedBlockingQueue(10))
.visit(c->"blocking", c->"not")
//"blocking
queue
- Queue to pattern match on