@CliCommand(value = DISPLAY_COUNTER, help = "Display the value of a field value counter") public List<Object> display( @CliOption(key = { "", "name" }, help = "the name of the field value counter to display", mandatory = true, optionContext = "existing-field-value-counter disable-string-converter") String name, final @CliOption(key = "pattern", help = "the pattern used to format the values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { FieldValueCounterResource counter = fvcOperations().retrieve(name); LinkedHashMap<String, Object> header = new LinkedHashMap<>(); header.put("key", "Value"); header.put("value", "Count"); TableModel model = new BeanListTableModel<>(counter.getValues().entrySet(), header); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Double.class)) .addFormatter(new Formatter() { @Override public String[] format(Object value) { return new String[] { pattern.format(value) }; } }).addAligner(SimpleHorizontalAligner.right).build(); return Arrays.asList(String.format("Displaying values for field value counter '%s'", name), table); }
@CliCommand(value = DISPLAY_COUNTER, help = "Display the value of a field value counter") public List<Object> display( @CliOption(key = { "", "name" }, help = "the name of the field value counter to display", mandatory = true, optionContext = "existing-field-value-counter disable-string-converter") String name, final @CliOption(key = "pattern", help = "the pattern used to format the values (see DecimalFormat)", mandatory = false, unspecifiedDefaultValue = NumberFormatConverter.DEFAULT) NumberFormat pattern) { FieldValueCounterResource counter = fvcOperations().retrieve(name); LinkedHashMap<String, Object> header = new LinkedHashMap<>(); header.put("key", "Value"); header.put("value", "Count"); TableModel model = new BeanListTableModel<>(counter.getValues().entrySet(), header); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Double.class)) .addFormatter(new Formatter() { @Override public String[] format(Object value) { return new String[] { pattern.format(value) }; } }).addAligner(SimpleHorizontalAligner.right).build(); return Arrays.asList(String.format("Displaying values for field value counter '%s'", name), table); }