예제 #1
0
 public static CoordinateMapKey getDiagnalCellKey(LCSCell lcsCell) {
   CoordinateMapKey key = null;
   if (lcsCell != null) {
     key = new CoordinateMapKey(lcsCell.getXCoordinate() - 1, lcsCell.getYCoordinate() - 1);
   }
   return key;
 }
예제 #2
0
 public static CoordinateMapKey getCurrentCellKey(LCSCell lcsCell) {
   CoordinateMapKey key = null;
   if (lcsCell != null) {
     key = new CoordinateMapKey(lcsCell.getXCoordinate(), lcsCell.getYCoordinate());
   }
   return key;
 }
예제 #3
0
 public static Direction getMovedDirection(LCSCell from, LCSCell to) {
   Direction direction = null;
   if (from != null && to != null) {
     direction =
         Direction.getDirection(
             from.getXCoordinate(),
             from.getYCoordinate(),
             to.getXCoordinate(),
             to.getYCoordinate());
   }
   return direction;
 }
예제 #4
0
  public void processCells(LCSCell[] lcsCells) {
    if (lcsCells != null) {
      List<Stack<LCSCell>> currentStackList = null;
      Stack<LCSCell> newStack = null;
      Direction movedDirection = null;
      for (LCSCell lcsCell : lcsCells) {
        //				if(lcsCell != null)
        currentStackList = this.walkedStackMap.get(lcsCell.getCoordinate());
        //				if(this.walkedStackMap.size() == 0 && lcsCell.getCoordinate() != null)
        if (currentStackList == null) {
          // first element
          currentStackList = new ArrayList<Stack<LCSCell>>();
          newStack = new Stack<LCSCell>();
          switch (lcsCell.getInheritDirection()) {
            case DIAGONAL:
              {
                newStack.push(lcsCell);
                currentStackList.add(newStack);
                this.walkedStackMap.put(
                    BacktrackSolver.createDiagnalCoordinate(lcsCell.getCoordinate()),
                    currentStackList);
                break;
              }
            case TOP:
              {
                currentStackList.add(newStack);
                this.walkedStackMap.put(
                    BacktrackSolver.createTopCoordinate(lcsCell.getCoordinate()), currentStackList);
                break;
              }
            case LEFT:
              {
                currentStackList.add(newStack);
                this.walkedStackMap.put(
                    BacktrackSolver.createLeftCoordinate(lcsCell.getCoordinate()),
                    currentStackList);
                break;
              }
            case TOP_AND_LEFT:
              {
                currentStackList.add(newStack);
                this.walkedStackMap.put(
                    BacktrackSolver.createTopCoordinate(lcsCell.getCoordinate()), currentStackList);
                this.walkedStackMap.put(
                    BacktrackSolver.createLeftCoordinate(lcsCell.getCoordinate()),
                    BacktrackSolver.shallowCloneStackList(currentStackList));
                break;
              }
            default:
              {
                break;
              }
          }
        } else {
          // ONLY PUSH MATCHES (DIAGONAL) AND SPLITS (TOP AND LEFT) ON STACK
          switch (lcsCell.getInheritDirection()) {
            case DIAGONAL:
              {
                BacktrackSolver.pushOnStacks(lcsCell, currentStackList);
                this.moveCellStacksDiagonal(lcsCell.getCoordinate());
                break;
              }
            case TOP:
              {
                this.moveCellStacksTop(lcsCell.getCoordinate());
                break;
              }
            case LEFT:
              {
                this.moveCellStacksLeft(lcsCell.getCoordinate());
                break;
              }
            case TOP_AND_LEFT:
              {
                this.walkedStackMap.remove(BacktrackSolver.getCurrentCellKey(lcsCell));

                if (this.walkedStackMap.containsKey(BacktrackSolver.getTopCellKey(lcsCell))) {
                  // add all of my cell stacks to that list as well, since the next cell is relevant
                  // to all of us now
                  //
                  //	cellStackMap.get(BacktrackSolver.getTopCellHash(lcsCell)).addAll(cellStackList);
                  this.walkedStackMap
                      .get(BacktrackSolver.getTopCellKey(lcsCell))
                      .addAll(BacktrackSolver.shallowCloneStackList(currentStackList));
                } else {
                  //								this.walkedStackMap.put(BacktrackSolver.getTopCellKey(lcsCell),
                  // BacktrackSolver.shallowCloneStackList(currentStackList));
                  //								cellStackMap.put(BacktrackSolver.getTopCellHash(lcsCell),
                  // cellStackList);
                }

                if (this.walkedStackMap.containsKey(BacktrackSolver.getLeftCellKey(lcsCell))) {
                  // add all of my cell stacks to that list as well, since the next cell is relevant
                  // to all of us now
                  //
                  //	cellStackMap.get(BacktrackSolver.getLeftCellHash(lcsCell)).addAll(cellStackList);
                  this.walkedStackMap
                      .get(BacktrackSolver.getLeftCellKey(lcsCell))
                      .addAll(BacktrackSolver.shallowCloneStackList(currentStackList));
                } else {
                  //								this.walkedStackMap.put(BacktrackSolver.getLeftCellKey(lcsCell),
                  // BacktrackSolver.shallowCloneStackList(currentStackList));
                  //
                  //	cellStackMap.put(BacktrackSolver.getLeftCellHash(lcsCell),(List<Stack<LCSCell>>)((ArrayList<Stack<LCSCell>>)cellStackList).clone());
                }
                break;
              }
            default:
              {
                break;
              }
          } // end switch
        }
      }
    }
  }