public static<T> void firstPlusSecond(final StepList<T> first, final ReadonlyList<T> second, final Comparator<T> comparator, @Nullable final Consumer<T> beforeAddListener, final Processor<T> filter) { if (second.getSize() == 0) return; int idx = stolenBinarySearch(first, second.get(0), comparator, 0); if (idx < 0) { idx = - (idx + 1); } // for group headers to not be left alone without its group if (idx > 0 && (! filter.process(first.get(idx - 1)))) { -- idx; if (idx > 0) --idx; } final ReadonlyList<T> remergePart = first.cut(idx); merge(remergePart, second, comparator, new Consumer<T>() { @Override public void consume(T t) { if (beforeAddListener != null) { beforeAddListener.consume(t); } first.add(t); } }, filter); }
private void doForGroup(T t, StepList<T> first) { final S newGroup = getGroup(t); if (newGroup != null && ! Comparing.equal(newGroup, myCurrentGroup)) { first.add(wrapGroup(newGroup, t)); myCurrentGroup = newGroup; } }