Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1.  public List<Integer> storeDialogs(List<Dialog> newDialogs)
  2.     {
  3.         boolean dialogsUpdated = false;
  4.         List<Integer> updatedIds = new ArrayList<Integer>();
  5.  
  6.         for (Dialog oldDialog : this.dialogs)
  7.         {
  8.             for (Dialog newDialog : newDialogs)
  9.             {
  10.                 if (newDialog.equals(oldDialog) && newDialog.getUpdatedAt().compareTo(oldDialog.getUpdatedAt()) > 0)
  11.                 {
  12.                     dialogsUpdated = true;
  13.                     updatedIds.add(newDialog.getUser().getId());
  14.                 }
  15.             }
  16.         }
  17.  
  18.         if (dialogsUpdated)
  19.         {
  20.             Set<Dialog> dialogsSet = new HashSet<Dialog>(this.dialogs);
  21.             dialogsSet.removeAll(newDialogs);
  22.             dialogsSet.addAll(newDialogs);
  23.             setDialogs(new ArrayList<Dialog>(dialogsSet));
  24.         }
  25.         else if (this.dialogs.size() == 0)
  26.         {
  27.             setDialogs(newDialogs);
  28.         }
  29.  
  30.         return updatedIds;
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement