Пример #1
0
 @Override
 public Long2ObjectMap<List<Event>> get() {
   Long2ObjectMap<ImmutableList.Builder<Event>> table =
       new Long2ObjectOpenHashMap<ImmutableList.Builder<Event>>();
   Cursor<Event> events = eventDAO.streamEvents();
   try {
     for (Event evt : events) {
       final long iid = evt.getItemId();
       ImmutableList.Builder<Event> list = table.get(iid);
       if (list == null) {
         list = new ImmutableList.Builder<Event>();
         table.put(iid, list);
       }
       list.add(evt);
     }
   } finally {
     events.close();
   }
   Long2ObjectMap<List<Event>> result = new Long2ObjectOpenHashMap<List<Event>>(table.size());
   for (Long2ObjectMap.Entry<ImmutableList.Builder<Event>> evt : table.long2ObjectEntrySet()) {
     result.put(evt.getLongKey(), evt.getValue().build());
     evt.setValue(null);
   }
   return result;
 }
Пример #2
0
 @Override
 public Long2ObjectMap<UserHistory<Event>> get() {
   Long2ObjectMap<List<Event>> table = new Long2ObjectOpenHashMap<List<Event>>();
   Cursor<Event> events = eventDAO.streamEvents();
   try {
     for (Event evt : events) {
       final long iid = evt.getUserId();
       List<Event> list = table.get(iid);
       if (list == null) {
         list = Lists.newArrayList();
         table.put(iid, list);
       }
       list.add(evt);
     }
   } finally {
     events.close();
   }
   Long2ObjectMap<UserHistory<Event>> result =
       new Long2ObjectOpenHashMap<UserHistory<Event>>(table.size());
   for (Long2ObjectMap.Entry<List<Event>> evt : table.long2ObjectEntrySet()) {
     long user = evt.getLongKey();
     result.put(user, History.forUser(user, evt.getValue()));
     evt.setValue(null);
   }
   return result;
 }
 private void ensureTagCache() {
   if (tagCache == null) {
     synchronized (this) {
       if (tagCache == null) {
         tagCache = new Long2ObjectOpenHashMap<List<String>>();
         ImmutableSet.Builder<String> vocabBuilder = ImmutableSet.builder();
         Cursor<String[]> lines = null;
         try {
           lines = new DelimitedTextCursor(tagFile, ",");
         } catch (FileNotFoundException e) {
           throw new DataAccessException("cannot open file", e);
         }
         try {
           for (String[] line : lines) {
             long mid = Long.parseLong(line[0]);
             List<String> tags = tagCache.get(mid);
             if (tags == null) {
               tags = new ArrayList<String>();
               tagCache.put(mid, tags);
             }
             tags.add(line[1]);
             vocabBuilder.add(line[1]);
           }
         } finally {
           lines.close();
         }
         vocabCache = vocabBuilder.build();
       }
     }
   }
 }
Пример #4
0
 @Override
 public LongSet get() {
   LongSet us = new LongOpenHashSet();
   Cursor<Event> events = eventDAO.streamEvents();
   try {
     for (Event e : events.fast()) {
       us.add(e.getUserId());
     }
   } finally {
     events.close();
   }
   return us;
 }
 private Long2ObjectMap<String> loadTitleCache() {
   Long2ObjectMap<String> cache = new Long2ObjectOpenHashMap<String>();
   Cursor<String[]> lines = null;
   try {
     lines = new DelimitedTextCursor(titleFile, ",");
   } catch (FileNotFoundException e) {
     throw new DataAccessException("cannot open file", e);
   }
   try {
     for (String[] line : lines) {
       long mid = Long.parseLong(line[0]);
       cache.put(mid, line[1]);
     }
   } finally {
     lines.close();
   }
   return cache;
 }