/** Partitions the windowGroups into SortGroups based on compatible order by exprs. */ private List<SortGroup> collectSortGroups(List<WindowGroup> windowGroups) { List<SortGroup> sortGroups = Lists.newArrayList(); for (WindowGroup windowGroup : windowGroups) { boolean match = false; for (SortGroup sortGroup : sortGroups) { if (sortGroup.isCompatible(windowGroup)) { sortGroup.add(windowGroup); match = true; break; } } if (!match) sortGroups.add(new SortGroup(windowGroup)); } return sortGroups; }