package com.coloryr.allmusic.server.bstats.charts; import com.coloryr.allmusic.server.bstats.json.JsonObjectBuilder; import java.util.Map; import java.util.concurrent.Callable; public class SimpleBarChart extends CustomChart { private final Callable> callable; /** * Class constructor. * * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SimpleBarChart(String chartId, Callable> callable) { super(chartId); this.callable = callable; } @Override protected JsonObjectBuilder.JsonObject getChartData() throws Exception { JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } for (Map.Entry entry : map.entrySet()) { valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()}); } return new JsonObjectBuilder() .appendField("values", valuesBuilder.build()) .build(); } }