Advertisement
Guest User

Untitled

a guest
May 27th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. private static List<AccountAction> merge(List<? extends AccountAction>... lists) {
  2.         int size = 0;
  3.         for (List<? extends AccountAction> actions : lists) {
  4.             size += actions.size();
  5.         }
  6.         List<AccountAction> actions = new ArrayList<>(size);
  7.         int[] counters = new int[lists.length];
  8.         while (actions.size() < size) {
  9.             int n = -1;
  10.             int version = Integer.MAX_VALUE;
  11.             for (int i = 0; i < lists.length; i++) {
  12.                 int counter = counters[i];
  13.                 if (counter < lists[i].size()) {
  14.                     AccountAction a = lists[i].get(counter);
  15.                     if (a.getVersion() < version) {
  16.                         n = i;
  17.                     }
  18.                 }
  19.             }
  20.             actions.add(lists[n].get(counters[n]++));
  21.         }
  22.         return actions;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement