Esempio n. 1
0
 public TextGrid getSubGrid(int x, int y, int width, int height) {
   TextGrid grid = new TextGrid(width, height);
   for (int i = 0; i < height; i++) {
     grid.setRow(i, new StringBuilder(getRow(y + i).subSequence(x, x + width)));
   }
   return grid;
 }
Esempio n. 2
0
 public CellSet followCell(Cell cell, Cell blocked) {
   if (isIntersection(cell)) return followIntersection(cell, blocked);
   if (isCorner(cell)) return followCorner(cell, blocked);
   if (isLine(cell)) return followLine(cell, blocked);
   if (isStub(cell)) return followStub(cell, blocked);
   if (isCrossOnLine(cell)) return followCrossOnLine(cell, blocked);
   System.err.println("Umbiguous input at position " + cell + ":");
   TextGrid subGrid = getTestingSubGrid(cell);
   subGrid.printDebug();
   throw new RuntimeException("Cannot follow cell " + cell + ": cannot determine cell type");
 }
Esempio n. 3
0
 public boolean equals(TextGrid grid) {
   if (grid.getHeight() != this.getHeight() || grid.getWidth() != this.getWidth()) {
     return false;
   }
   int height = grid.getHeight();
   for (int i = 0; i < height; i++) {
     String row1 = this.getRow(i).toString();
     String row2 = grid.getRow(i).toString();
     if (!row1.equals(row2)) return false;
   }
   return true;
 }
Esempio n. 4
0
 public void copyCellsTo(CellSet cells, TextGrid grid) {
   for (Cell cell : cells) {
     grid.set(cell, this.get(cell));
   }
 }
Esempio n. 5
0
 public boolean matchesAny(Cell cell, GridPatternGroup criteria) {
   TextGrid subGrid = getTestingSubGrid(cell);
   return subGrid.matchesAny(criteria);
 }
Esempio n. 6
0
 public TextGrid(TextGrid otherGrid) {
   rows = new ArrayList<StringBuilder>();
   for (StringBuilder row : otherGrid.getRows()) {
     rows.add(new StringBuilder(row));
   }
 }
Esempio n. 7
0
 public static TextGrid makeSameSizeAs(TextGrid grid) {
   return new TextGrid(grid.getWidth(), grid.getHeight());
 }