private static Pair<Integer, TableCell> getTableCell(List<Pair<Boolean, List<Integer>>> tree,
                                                        List<XmlTag> tags,
                                                        int index,
                                                        XmlTag tag, int currentColumn,
                                                        int currentRow, TableRow current, TableRow previous) {
    int add = 0;
    TableCell answer = null;
    XmlTag element = tags.get(index);
    if (TD.equals(StringUtil.toLowerCase(element.getLocalName())) || TH.equals(StringUtil.toLowerCase(element.getLocalName()))) {
      int cols = getColumnsNumber(element);
      int rows = getRowsNumber(element);

      for (int i = currentColumn; i < previous.size() && previous.get(i).getRemainingRowsNumber(currentRow) > 0; i++) {
        current.add(previous.get(i));
        add++;
      }
      TableCell cell = new TableCell(element, currentRow, currentColumn + add, rows, cols);
      if (tag == element) {
        answer = cell;
      }
      for (int i = 0; i < cols; i++) {
        current.add(cell);
      }
      add += cols;
    }
    for (int child : tree.get(index).second) {
      Pair<Integer, TableCell> tmp = getTableCell(tree, tags, child, tag, currentColumn + add, currentRow, current, previous);
      if (tmp.second != null) {
        answer = tmp.second;
      }
      add += tmp.first.intValue();
    }

    return new Pair<>(add, answer);
  }
private static Pair<Integer, TableCell> getTableCell(List<Pair<Boolean, List<Integer>>> tree,
                                                        List<XmlTag> tags,
                                                        int index,
                                                        XmlTag tag, int currentColumn,
                                                        int currentRow, TableRow current, TableRow previous)