Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Optimized OptimizedGenericBooleanPrefDataModel

By: a guest on Dec 2nd, 2011  |  syntax: Java  |  size: 1.33 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData, FastByIDMap<FastByIDMap<Long>> timestamps) {
  2.             Preconditions.checkArgument(userData != null, "userData is null");
  3.  
  4.             this.preferenceFromUsers = userData;
  5.             this.preferenceForItems = new FastByIDMap<FastIDSet>();
  6.             FastIDSet itemIDSet = new FastIDSet();
  7.             for (Map.Entry<Long, FastIDSet> entry : preferenceFromUsers.entrySet()) {
  8.               long userID = entry.getKey();
  9.               FastIDSet itemIDs = entry.getValue();
  10.               itemIDSet.addAll(itemIDs);
  11.               if (itemIDs.size() > 1) {
  12.                       LongPrimitiveIterator it = itemIDs.iterator();
  13.                       while (it.hasNext()) {
  14.                         long itemID = it.nextLong();
  15.                         FastIDSet userIDs = preferenceForItems.get(itemID);
  16.                         if (userIDs == null) {
  17.                           userIDs = new FastIDSet(2);
  18.                           preferenceForItems.put(itemID, userIDs);
  19.                         }
  20.                         userIDs.add(userID);
  21.                       }
  22.               }
  23.             }
  24.  
  25.             this.itemIDs = itemIDSet.toArray();
  26.             itemIDSet = null; // Might help GC -- this is big
  27.             Arrays.sort(itemIDs);
  28.  
  29.             this.userIDs = new long[userData.size()];
  30.             int i = 0;
  31.             LongPrimitiveIterator it = userData.keySetIterator();
  32.             while (it.hasNext()) {
  33.               userIDs[i++] = it.next();
  34.             }
  35.             Arrays.sort(userIDs);
  36.  
  37.             this.timestamps = timestamps;
  38.           }
  39.