public static String getShortestTableStringFormat(List<List<String>> table)
    {
        if (table.isEmpty()) {
            throw new IllegalArgumentException("Table must include at least one row");
        }

        int tableWidth = table.get(0).size();
        int[] lengthTracker = new int[tableWidth];
        for (List<String> row : table) {
            if (row.size() != tableWidth) {
                String errorString = format("All rows in the table are expected to have exactly same number of columns: %s != %s",
                        tableWidth, row.size());
                throw new IllegalArgumentException(errorString);
            }

            for (int i = 0; i < row.size(); i++) {
                lengthTracker[i] = max(row.get(i).length(), lengthTracker[i]);
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append('|');
        for (int maxLen : lengthTracker) {
            sb.append(" %-")
                    .append(maxLen)
                    .append("s |");
        }

        return sb.toString();
    }
@Test
    public void testGetShortestTableStringFormatBadInput()
    {
        List<List<String>> table = Arrays.asList(
                Arrays.asList("Header1", "Header2", "Headr3"),
                Arrays.asList("Value1", "Value2"),
                Arrays.asList("LongValue1", "SVal2", "SVal3"));

        assertThrows(
                IllegalArgumentException.class,
                () -> StringTableUtils.getShortestTableStringFormat(table));
    }