RunJob { protected static void outputDriversTable(Map<String, DriverMeta> driversMap) { String[] colNames = new String[] {"Name","Description","Ver","Class"}; String[] aligns = new String[] {"-","-","-","-"}; int maxDescriptionWidth = 48; int widths[] = new int[colNames.length]; for (int i = 0; i < colNames.length; i ++) { widths[i] = colNames[i].length(); } int padding = 2; for (Entry<String, DriverMeta> e : driversMap.entrySet()) { if (!e.getValue().hidden) { int i = 0; widths[i] = Math.max(e.getKey().length(), widths[i]); widths[i+1] = Math.min(Math.max(e.getValue().description.length(), widths[i+1]), maxDescriptionWidth); widths[i+2] = Math.max(e.getValue().version.length(), widths[i+2]); widths[i+3] = Math.max(e.getValue().driverClass.getName().length(), widths[i+3]); } } int width = padding * widths.length-1; for (int w : widths) { width+= w; } String sep = StringUtils.repeat("=", width); System.out.println(sep); System.out.println(StringUtils.center("A V A I L A B L E D R I V E R S", width)); System.out.println(sep); String[] underscores = new String[colNames.length]; StringBuilder headersFormatSb = new StringBuilder(); StringBuilder valuesFormatSb = new StringBuilder(); for (int i = 0; i < widths.length; i++) { headersFormatSb.append("%-").append(widths[i] + padding).append("s"); valuesFormatSb.append("%").append(aligns[i]).append(widths[i] + padding).append("s"); underscores[i] = StringUtils.repeat("-", widths[i]); } String format = headersFormatSb.toString(); System.out.format(format, (Object[])colNames); System.out.println(); System.out.format(format, (Object[])underscores); System.out.println(); format = valuesFormatSb.toString(); List<String> descriptionLines = new ArrayList<>(); for (Entry<String, DriverMeta> e : driversMap.entrySet()) { if (!e.getValue().hidden) { descriptionLines.clear(); String description = e.getValue().description; if (description.length() > maxDescriptionWidth) { splitLine(descriptionLines, description, maxDescriptionWidth); description = descriptionLines.remove(0); } System.out.format(format, e.getKey(), description, StringUtils.center(e.getValue().version, widths[2]), e.getValue().driverClass.getName()); System.out.println(); while(!descriptionLines.isEmpty()) { System.out.format(format, "", descriptionLines.remove(0), "", ""); System.out.println(); } } } }  static void main(String[] args); static final String SYSPROP_DRIVER_SCAN_PACKAGES; static final String RESOURCE_DRIVER_SCAN_PACKAGES; }
@Test @SuppressWarnings({"unchecked"}) public void testOutputDrivers() { Map<String, DriverMeta> drivers = new HashMap<>(); Class<? extends ToolListener<?>> nullListener = null; drivers.put("driverB", new DriverMeta("driverA", "short description", "N/A", AnotherTest.class, nullListener)); drivers.put("driverC", new DriverMeta("driverA", "a very very long description for this driver that we need to wrap.", "123.0.3839-SNAPSHOT", AnotherTest.class, nullListener)); drivers.put("driverA", new DriverMeta("driverA", "", "N/A", AnotherTest.class, nullListener)); RunJob.outputDriversTable(drivers); }