@Test public void testFormatWithFullMatrix() { GameMatrix matrix = gameMatrixFactory.newGameMatrix(); matrix.setAll(QuadraticArrays.parse( "294731856", "781465239", "536829741", "673158924", "819246573", "425973168", "358612497", "942387615", "167594382")); AbstractTextFormatter formatter = newInstance(); formatter.setUnknownCellContentCharacter("?"); String actual = formatter.format(matrix); assertEquals( "| | | | | | | | | |\n"+ "|---|---|---|---|---|---|---|---|---|\n"+ "| 2 | 9 | 4 | 7 | 3 | 1 | 8 | 5 | 6 |\n"+ "| 7 | 8 | 1 | 4 | 6 | 5 | 2 | 3 | 9 |\n"+ "| 5 | 3 | 6 | 8 | 2 | 9 | 7 | 4 | 1 |\n"+ "| 6 | 7 | 3 | 1 | 5 | 8 | 9 | 2 | 4 |\n"+ "| 8 | 1 | 9 | 2 | 4 | 6 | 5 | 7 | 3 |\n"+ "| 4 | 2 | 5 | 9 | 7 | 3 | 1 | 6 | 8 |\n"+ "| 3 | 5 | 8 | 6 | 1 | 2 | 4 | 9 | 7 |\n"+ "| 9 | 4 | 2 | 3 | 8 | 7 | 6 | 1 | 5 |\n"+ "| 1 | 6 | 7 | 5 | 9 | 4 | 3 | 8 | 2 |\n"+ "| | | | | | | | | |\n" , actual); }
@Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); } }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  @Override String format(final GameMatrix matrix); }
MarkdownTableFormatter extends AbstractTextFormatter { @Override public String format(final GameMatrix matrix) { StringBuilder sb = new StringBuilder(); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append("---"); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte val = matrix.get(row, column); String str; if (val == GameMatrix.UNSET) { str = getUnknownCellContentCharacter(); } else { str = Integer.toString(val); } if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(str); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); } for (int column = 0; column < GameMatrix.SIZE; column++) { if (column == 0) { sb.append(TABLE_SEPARATOR); } sb.append(" "); sb.append(" "); sb.append(TABLE_SEPARATOR); } sb.append(getLineSeparator()); return sb.toString(); }  @Override String format(final GameMatrix matrix);  }