public String getAsUSStateAreas(UserAppContext appContext, long timeKey, String profilerName) { MetricProfilerDao dao = HostContext.getMiniProfilerDao(); MetricProfiler profiler = dao.loadProfiler(appContext, timeKey, profilerName); if (profiler == null || profiler.getDetail() == null) { return "[]"; } List<AmchartDataProviderIdValue> areas = new ArrayList<AmchartDataProviderIdValue>(); for (MetricProfilerDataItem entry : profiler.getDetail()) { String stateName = entry.getName(); String code = USGeoUtil.getISOCodeByName(stateName); if (code == null || code.equals("")) { logger.warn("Invalid state name in profiler data: " + stateName); continue; } AmchartDataProviderIdValue idValue = new AmchartDataProviderIdValue(); idValue.setId(code); idValue.setValue(entry.getValue()); areas.add(idValue); } Collections.sort(areas, new AmchartDataProviderIdValueComparator()); return new Gson().toJson(areas); }
@Override public int compare(AmchartDataProviderIdValue o1, AmchartDataProviderIdValue o2) { return StringComparator.INSTANCE.compare(o1.getId(), o2.getId()); }