private static void getAllReceiveMessages(Source input, List<ReceiveMessage> result) { if (input instanceof SimpleSource) { result.add(((SimpleSource) input).getMessage()); } else if (input instanceof SourceComposition) { SourceComposition composition = (SourceComposition) input; for (Source s : composition.getSources()) { getAllReceiveMessages(s, result); } } }
public static List<ReceiveMessage> allReceiveMessages(Source input) { List<ReceiveMessage> result = new ArrayList<>(); getAllReceiveMessages(input, result); return result; }