private Table displayAggrCounter(AggregateCounterResource aggResource, final NumberFormat pattern) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("key", "TIME"); headers.put("value", "COUNT"); TableModel model = new BeanListTableModel<>(aggResource.getValues().entrySet(), headers); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Long.class)) .addFormatter(value -> new String[] { pattern.format(value) }).addAligner(SimpleHorizontalAligner.right).build(); return table; }
private Table displayAggrCounter(AggregateCounterResource aggResource, final NumberFormat pattern) { LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("key", "TIME"); headers.put("value", "COUNT"); TableModel model = new BeanListTableModel<>(aggResource.getValues().entrySet(), headers); Table table = DataFlowTables.applyStyle(new TableBuilder(model)).on(CellMatchers.ofType(Long.class)) .addFormatter(value -> new String[] { pattern.format(value) }).addAligner(SimpleHorizontalAligner.right).build(); return 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); }
@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); }
/** * Install all the necessary formatters, aligners, etc for key-value rendering of Maps. */ public static TableBuilder configureKeyValueRendering(TableBuilder builder, String delimiter) { return builder.on(CellMatchers.ofType(Map.class)) .addFormatter(new MapFormatter(delimiter)) .addAligner(new KeyValueHorizontalAligner(delimiter.trim())) .addSizer(new KeyValueSizeConstraints(delimiter)) .addWrapper(new KeyValueTextWrapper(delimiter)).and(); } }
builder.on(CellMatchers.column(0)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleHorizontalAligner.center) .on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center);
builder.on(CellMatchers.column(0)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleHorizontalAligner.center) .on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center);
builder.on(CellMatchers.ofType(FeatureInfo.class)).addFormatter(new DataFlowTables.BeanWrapperFormatter(": ")) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(value -> ((List<String>) value).toArray(new String[0])); builder.on(CellMatchers.ofType(RuntimeEnvironmentDetails.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo")))
builder.on(CellMatchers.ofType(FeatureInfo.class)).addFormatter(new DataFlowTables.BeanWrapperFormatter(": ")) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") : Arrays.asList("roles", "class", "username"); builder.on(CellMatchers.ofType(SecurityInfo.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, excludes)) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); builder.on(CellMatchers.ofType(List.class)) .addFormatter(value -> ((List<String>) value).toArray(new String[0])); builder.on(CellMatchers.ofType(RuntimeEnvironmentDetails.class)) .addFormatter(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo")))