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); }
builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER).fromTopLeft().toBottomRight() .on(CellMatchers.table()).addAligner(SimpleHorizontalAligner.center).on(CellMatchers.table()) .addAligner(SimpleVerticalAligner.middle); .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") 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(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP)
builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER).fromTopLeft().toBottomRight() .on(CellMatchers.table()).addAligner(SimpleHorizontalAligner.center).on(CellMatchers.table()) .addAligner(SimpleVerticalAligner.middle); .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); List<String> excludes = securityInfo.isAuthenticated() ? Arrays.asList("roles", "class") 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(new DataFlowTables.BeanWrapperFormatter(": ", null, Arrays.asList("class", "platformSpecificInfo"))) .addAligner(new KeyValueHorizontalAligner(":")).addSizer(new KeyValueSizeConstraints(": ")) .addWrapper(new KeyValueTextWrapper(": ")); rowsWithThinSeparators.forEach(row -> builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP)
final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); 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);
final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); 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);
/** * Customize the given TableBuilder with the following common features (these choices can * always be overridden by applying later customizations) : * <ul> * <li>double border around the whole table and first row</li> * <li>vertical space (air) borders, single line separators between rows</li> * <li>first row is assumed to be a header and is centered horizontally and * vertically</li> * <li>cells containing Map values are rendered as {@literal key = value} lines, trying to * align on equal signs</li> * </ul> * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyle(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft() .toBottomRight() .addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0)) .addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center); return Tables.configureKeyValueRendering(builder, " = "); }
/** * Customize the given TableBuilder with the following common features (these choices * can always be overridden by applying later customizations) : * <ul> * <li>double border around the whole table and first row</li> * <li>vertical space (air) borders, single line separators between rows</li> * <li>first row is assumed to be a header and is centered horizontally and * vertically</li> * <li>cells containing Map values are rendered as {@literal key = value} lines, * trying to align on equal signs</li> * </ul> * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyle(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0)) .addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center); return Tables.configureKeyValueRendering(builder, " = "); }
/** * Customize the given TableBuilder with the following common features (these choices * can always be overridden by applying later customizations) : * <ul> * <li>double border around the whole table and first row</li> * <li>vertical space (air) borders, single line separators between rows</li> * <li>first row is assumed to be a header and is centered horizontally and * vertically</li> * <li>cells containing Map values are rendered as {@literal key = value} lines, * trying to align on equal signs</li> * </ul> * * @param builder the table builder to use * @return the configured table builder */ public static TableBuilder applyStyle(TableBuilder builder) { builder.addOutlineBorder(BorderStyle.fancy_double) .paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight() .addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0)) .addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center); return Tables.configureKeyValueRendering(builder, " = "); }
@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(); } }