public void store(String packageName) {
    Log.d("HarvestJournal", "store");
    HashMap sessions;

    if (data.containsKey(packageName)) {
      sessions = (HashMap) data.get(packageName);
    } else {
      sessions = new HashMap();
      data.put(packageName, sessions);
    }

    Long started = settings.getStarted(null);
    HarvestEntry entry;

    if (sessions.containsKey(started)) {
      entry = (HarvestEntry) sessions.get(started);
    } else {
      entry = new HarvestEntry(packageName);
      entry.started = started;
      sessions.put(started, entry);
    }

    Long delta = settings.getRealNowSeconds() - lastStored;
    if (delta > HarvestSettings.INTERVAL) {
      delta = HarvestSettings.INTERVAL;
    }

    entry.increment(delta);
    Log.d(
        "HarvestJournal",
        String.format("%s %d %d", entry.packageName, entry.started, entry.duration));

    display();
  }
 public HarvestJournal(Context context) {
   Log.d("HarvestJournal", "created");
   data = new HashMap();
   storage = new HarvestStore(context);
   settings = new HarvestSettings(context);
   lastPersisted = settings.getRealNowSeconds();
   lastStored = settings.getRealNowSeconds();
 }
  public void dump() {
    Log.d("HarvestJournal", "dump");
    for (String packageName : (Set<String>) data.keySet()) {
      HashMap sessions = (HashMap) data.get(packageName);

      for (Long started : (Set<Long>) sessions.keySet()) {
        HarvestEntry entry = (HarvestEntry) sessions.get(started);
        storage.persist(entry);
      }
    }

    data.clear();
    lastPersisted = settings.getRealNowSeconds();
  }
 public Boolean canDump() {
   Log.d("HarvestJournal", "canDump");
   return ((settings.getRealNowSeconds() - lastPersisted) > HarvestSettings.PERSIST);
 }
 public List<HarvestEntry> getEntries() {
   Log.d("HarvestJournal", "getEntries");
   dump();
   Long started = settings.getStarted(settings.getLastReported());
   return storage.retrieve(started);
 }