Exemplo n.º 1
0
 public boolean isInterleaveableWith(Row<T> other) {
   if (other == null || other == this) {
     return false;
   } else if (other.getNextRow() != this && other.getPrevRow() != this) {
     return false;
   }
   Iterator<Cell<T>> oIt = other.iterator();
   for (Cell<T> c : this) {
     if (oIt.next().isUnpackable() && c.isUnpackable()) {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 2
0
    public boolean tryInterleaveWith(Row<T> other) {
      // System.out.println("Try to interleave " + this);
      // System.out.print("             with " + other);
      if (!isInterleaveableWith(other)) {
        // System.out.println(": failed");
        return false;
      }

      Iterator<Cell<T>> oIt = other.iterator();
      for (Cell<T> c : this) {
        Cell<T> oC = oIt.next();
        if (c.isFilled()) {
          if (oC.prevCell == null) {
            oC.parent.firstCell = c;
          } else {
            oC.prevCell.nextCell = c;
          }
          if (oC.nextCell == null) {
            oC.parent.lastCell = c;
          } else {
            oC.nextCell.prevCell = c;
          }

          c.prevCell = oC.prevCell;
          c.nextCell = oC.nextCell;
          c.parent = oC.parent;
          oC.nextCell = null;
          oC.prevCell = null;
          oC.parent = null;
        } else if (c.isUnpackable()) {
          oC.setPackable(false);
        }
      }
      this._remove();
      // System.out.println(": done");
      return true;
    }