Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1.     public static void popularity(Long id) {
  2.         Brand brand = Brand.findById(id);
  3.         notFoundIfNull(brand);
  4.         List<Outfit> outfits = Outfit.listByBrand(brand.id);
  5.         Map<Long, Integer> counter = new HashMap<Long, Integer>();
  6.         int view = 0;
  7.         for (Outfit outfit : outfits) {
  8.             incrementValue(counter, outfit.contact.id);
  9.             view += outfit.view;
  10.         }
  11.         List sorted = sortByValue(counter);
  12.         int i = 0;
  13.         List<Contact> contacts = new ArrayList<Contact>();
  14.         for (Iterator it = sorted.iterator(); i < 15 && it.hasNext();) {
  15.             i++;
  16.             Map.Entry entry = (Map.Entry)it.next();
  17.             Contact contact = Contact.findById((Long) entry.getKey());
  18.             contacts.add(contact);
  19.         }
  20.         brand.bestOutfiter = contacts;
  21.         brand.view = view;
  22.         brand.score = (view * outfits.size() / 2);
  23.         brand.update();
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement