Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static List<AccountAction> merge(List<? extends AccountAction>... lists) {
- int size = 0;
- for (List<? extends AccountAction> actions : lists) {
- size += actions.size();
- }
- List<AccountAction> actions = new ArrayList<>(size);
- int[] counters = new int[lists.length];
- while (actions.size() < size) {
- int n = -1;
- int version = Integer.MAX_VALUE;
- for (int i = 0; i < lists.length; i++) {
- int counter = counters[i];
- if (counter < lists[i].size()) {
- AccountAction a = lists[i].get(counter);
- if (a.getVersion() < version) {
- n = i;
- }
- }
- }
- actions.add(lists[n].get(counters[n]++));
- }
- return actions;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement