Skip to content

Instantly share code, notes, and snippets.

@marianogonzalez
Last active April 25, 2017 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marianogonzalez/8921049 to your computer and use it in GitHub Desktop.
Save marianogonzalez/8921049 to your computer and use it in GitHub Desktop.
public class CheapeastFlightAggregationStrategy implements AggregationStrategy {
@Override
public MuleEvent aggregate(AggregationContext context) throws MuleException {
MuleEvent result = null;
long value = Long.MAX_VALUE;
for (MuleEvent event : context.collectEventsWithoutExceptions()) {
Flight flight = (Flight) event.getMessage().getPayload();
if (flight.getCost() < value) {
result = DefaultMuleEvent.copy(event);
value = flight.getCost();
}
}
if (result != null) {
return result;
}
throw new RuntimeException("no flights obtained");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment