@@ -72,27 +72,28 @@ public Optional<Cell> getCell(int y, int x) {
7272 public String toString () {
7373 StringBuilder stringBuilder = new StringBuilder ();
7474 stringBuilder .append ("slice : \n " );
75- //output coordinates
76- int columnsCount = cells .stream ().max (Comparator .comparingInt (Cell ::getX )).get ().getX ();
77- int rowsCount = cells .stream ().max (Comparator .comparingInt (Cell ::getY )).get ().getY ();
78- //output columns coordinates
79- stringBuilder .append (" " );
80- for (int column = 0 ; column < columnsCount + 1 ; column ++) {
81- stringBuilder .append (" " ).append (column );
82- }
83- stringBuilder .append ("\n " );
84- for (int row = 0 ; row < rowsCount + 1 ; row ++) {
85- //output rows coordinates
86- stringBuilder .append (row ).append (" " );
75+ if (maxX ()+maxY () < 20 ) { //output coordinates
76+ int columnsCount = cells .stream ().max (Comparator .comparingInt (Cell ::getX )).get ().getX ();
77+ int rowsCount = cells .stream ().max (Comparator .comparingInt (Cell ::getY )).get ().getY ();
78+ //output columns coordinates
79+ stringBuilder .append (" " );
8780 for (int column = 0 ; column < columnsCount + 1 ; column ++) {
88- if (this .getCell (row , column ).isPresent ()) {
89- stringBuilder .append (this .getCell (row , column ).get ().toString ()).append (" " );
90- } else {
91- stringBuilder .append (" " ).append (" " );
92- }
81+ stringBuilder .append (" " ).append (column );
9382 }
9483 stringBuilder .append ("\n " );
95- }
84+ for (int row = 0 ; row < rowsCount + 1 ; row ++) {
85+ //output rows coordinates
86+ stringBuilder .append (row ).append (" " );
87+ for (int column = 0 ; column < columnsCount + 1 ; column ++) {
88+ if (this .getCell (row , column ).isPresent ()) {
89+ stringBuilder .append (this .getCell (row , column ).get ().toString ()).append (" " );
90+ } else {
91+ stringBuilder .append (" " ).append (" " );
92+ }
93+ }
94+ stringBuilder .append ("\n " );
95+ }
96+ } else stringBuilder .append ("\n size: " ).append (cells .size ());
9697 return stringBuilder .toString ().trim ();
9798 }
9899
0 commit comments