Last active
November 1, 2017 12:17
-
-
Save ChrisChinchilla/45542b334c8f28796e8fd53f3d1b020f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pattern<Shipment, ?> pattern = Pattern.<Shipment>begin("start").where(new SimpleCondition<Shipment>() { | |
@Override | |
public boolean filter(Shipment value) throws Exception { | |
// Check where the shipment came from | |
return value.from.equals("A"); | |
} | |
}).followedByAny("middle").where(new IterativeCondition<Shipment>() { | |
@Override | |
public boolean filter(Shipment value, Context<Shipment> ctx) throws Exception { | |
Iterator<Shipment> it = ctx.getEventsForPattern("middle").iterator(); | |
// Iterate through stops along the shipment route | |
if (!it.hasNext()) { | |
return ctx.getEventsForPattern("start").iterator().next().to.equals(value.from); | |
} | |
String to = null; | |
while (it.hasNext()) { | |
to = it.next().to; | |
} | |
return value.from.equals(to); | |
} | |
}).oneOrMore().followedByAny("end").where(new IterativeCondition<Shipment>() { | |
@Override | |
public boolean filter(Shipment value, Context<Shipment> ctx) throws Exception { | |
int counter = 0; | |
String to = null; | |
Iterator<Shipment> it = ctx.getEventsForPattern("middle").iterator(); | |
while (it.hasNext()) { | |
to = it.next().to; | |
counter++; | |
} | |
// Check if the shipment had at least 5 stops and that the from and to values are what we expect | |
return counter >= 5 && to.equals(value.from) && value.to.equals("B"); | |
} | |
}).within(Time.hours(24)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment