Ejemplo n.º 1
0
 public Map<String, String> getStatHistory(final Statistic statistic, final int days) {
   final Map<String, String> returnMap = new LinkedHashMap<>();
   DailyKey loopKey = currentDailyKey;
   int counter = days;
   while (counter > 0) {
     final StatisticsBundle bundle = getStatBundleForKey(loopKey.toString());
     if (bundle != null) {
       final String key = (new SimpleDateFormat("MMM dd")).format(loopKey.calendar().getTime());
       final String value = bundle.getStatistic(statistic);
       returnMap.put(key, value);
     }
     loopKey = loopKey.previous();
     counter--;
   }
   return returnMap;
 }
Ejemplo n.º 2
0
  public Map<DailyKey, String> getAvailableKeys(final Locale locale) {
    final DateFormat dateFormatter =
        SimpleDateFormat.getDateInstance(SimpleDateFormat.DEFAULT, locale);
    final Map<DailyKey, String> returnMap = new LinkedHashMap<DailyKey, String>();

    // add current time;
    returnMap.put(currentDailyKey, dateFormatter.format(new Date()));

    // if now historical data then we're done
    if (currentDailyKey.equals(initialDailyKey)) {
      return returnMap;
    }

    DailyKey loopKey = currentDailyKey;
    int safetyCounter = 0;
    while (!loopKey.equals(initialDailyKey) && safetyCounter < 5000) {
      final Calendar c = loopKey.calendar();
      final String display = dateFormatter.format(c.getTime());
      returnMap.put(loopKey, display);
      loopKey = loopKey.previous();
      safetyCounter++;
    }
    return returnMap;
  }