Example #1
0
 public CellSet followCorner4(Cell cell, Cell blocked) {
   if (!isCorner4(cell)) return null;
   CellSet result = new CellSet();
   if (!cell.getNorth().equals(blocked)) result.add(cell.getNorth());
   if (!cell.getEast().equals(blocked)) result.add(cell.getEast());
   return result;
 }
Example #2
0
  private CellSet seedFillOld(Cell seed, char newChar) {
    CellSet cellsFilled = new CellSet();
    char oldChar = get(seed);

    if (oldChar == newChar) return cellsFilled;
    if (isOutOfBounds(seed)) return cellsFilled;

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);
      cellsFilled.add(cell);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      if (get(sCell) == oldChar) stack.push(sCell);
      if (get(eCell) == oldChar) stack.push(eCell);
      if (get(wCell) == oldChar) stack.push(wCell);
    }

    return cellsFilled;
  }
Example #3
0
  public static void main1(String[] args) throws ClassNotFoundException, SQLException {
    OlapConnection conn = getConnection(url);
    CellSet cs = getResultSet(mdx, conn);
    // CellSetAxis c;

    int count = 0;
    if (cs.getAxes().size() > 1) {
      for (Position row : cs.getAxes().get(1)) {
        for (Position column : cs.getAxes().get(0)) {
          for (Member member : row.getMembers()) {
            System.out.println("rows:" + member.getUniqueName());
          }
          for (Member member : column.getMembers()) {
            System.out.println("columns:" + member.getUniqueName());
          }
          final Cell cell = cs.getCell(column, row);

          System.out.println("values:" + cell.getValue());

          Position[] positions = new Position[2];
          positions[0] = column;
          positions[1] = row;

          OlapCell oalpCell = new OlapCell(positions, cell.getValue());

          System.out.println("****" + oalpCell.toString());
          System.out.println(count++);
        }
      }
    }
  }
Example #4
0
 public static void main(String[] args) throws Exception {
   OlapConnection conn = getConnection(url);
   CellSet cs = getResultSet(mdx, conn);
   List<Position> coordinates = new ArrayList<Position>();
   List<OlapCell> results = new ArrayList<OlapCell>();
   explore(cs.getAxes(), coordinates, cs, results);
   Gson gson = new Gson();
   System.out.println(gson.toJson(results));
 }
Example #5
0
 public CellSet followCrossOnLine(Cell cell, Cell blocked) {
   CellSet result = new CellSet();
   if (isHorizontalCrossOnLine(cell)) {
     result.add(cell.getEast());
     result.add(cell.getWest());
   } else if (isVerticalCrossOnLine(cell)) {
     result.add(cell.getNorth());
     result.add(cell.getSouth());
   }
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Example #6
0
 public CellSet getAllBlanksBetweenCharacters() {
   CellSet set = new CellSet();
   int width = getWidth();
   int height = getHeight();
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
       Cell cell = new Cell(x, y);
       if (isBlankBetweenCharacters(cell)) set.add(cell);
     }
   }
   return set;
 }
Example #7
0
 public CellSet getAllBoundaries() {
   CellSet set = new CellSet();
   int width = getWidth();
   int height = getHeight();
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
       Cell cell = new Cell(x, y);
       if (isBoundary(cell)) set.add(cell);
     }
   }
   return set;
 }
Example #8
0
 public CellSet getAllNonBlank() {
   CellSet set = new CellSet();
   int width = getWidth();
   int height = getHeight();
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
       Cell cell = new Cell(x, y);
       if (!isBlank(cell)) set.add(cell);
     }
   }
   return set;
 }
Example #9
0
 /**
  * Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned)
  *
  * @return null if the cell is not a line
  */
 public CellSet followLine(Cell cell) {
   if (isHorizontalLine(cell)) {
     CellSet result = new CellSet();
     if (isBoundary(cell.getEast())) result.add(cell.getEast());
     if (isBoundary(cell.getWest())) result.add(cell.getWest());
     return result;
   } else if (isVerticalLine(cell)) {
     CellSet result = new CellSet();
     if (isBoundary(cell.getNorth())) result.add(cell.getNorth());
     if (isBoundary(cell.getSouth())) result.add(cell.getSouth());
     return result;
   }
   return null;
 }
Example #10
0
 public CellSet followIntersection(Cell cell, Cell blocked) {
   if (!isIntersection(cell)) return null;
   CellSet result = new CellSet();
   Cell cN = cell.getNorth();
   Cell cS = cell.getSouth();
   Cell cE = cell.getEast();
   Cell cW = cell.getWest();
   if (hasEntryPoint(cN, 6)) result.add(cN);
   if (hasEntryPoint(cS, 2)) result.add(cS);
   if (hasEntryPoint(cE, 8)) result.add(cE);
   if (hasEntryPoint(cW, 4)) result.add(cW);
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Example #11
0
 public CellSet getPointMarkersOnLine() {
   CellSet result = new CellSet();
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       char c = get(xi, yi);
       if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(new Cell(xi, yi))) {
         result.add(new Cell(xi, yi));
       }
     }
   }
   return result;
 }
Example #12
0
  /**
   * Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at <code>
   * seed</code>.
   */
  public CellSet findBoundariesExpandingFrom(Cell seed) {
    CellSet boundaries = new CellSet();
    char oldChar = get(seed);

    if (isOutOfBounds(seed)) return boundaries;

    char newChar = 1; // TODO: kludge

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      else if (get(nCell) == '*') boundaries.add(nCell);

      if (get(sCell) == oldChar) stack.push(sCell);
      else if (get(sCell) == '*') boundaries.add(sCell);

      if (get(eCell) == oldChar) stack.push(eCell);
      else if (get(eCell) == '*') boundaries.add(eCell);

      if (get(wCell) == oldChar) stack.push(wCell);
      else if (get(wCell) == '*') boundaries.add(wCell);
    }

    return boundaries;
  }
Example #13
0
 public CellSet followStub(Cell cell, Cell blocked) {
   if (!isStub(cell)) return null;
   CellSet result = new CellSet();
   if (isBoundary(cell.getEast())) result.add(cell.getEast());
   else if (isBoundary(cell.getWest())) result.add(cell.getWest());
   else if (isBoundary(cell.getNorth())) result.add(cell.getNorth());
   else if (isBoundary(cell.getSouth())) result.add(cell.getSouth());
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Example #14
0
  // coordinates.size should be 0 at very first
  public static void explore(
      List<CellSetAxis> axes, List<Position> coordinates, CellSet cs, List<OlapCell> cellList) {
    int level = coordinates.size();
    // System.out.println(level + "  " + axes.size());
    if (level < axes.size()) {
      for (Position p : axes.get(level).getPositions()) {
        coordinates.add(p);
        explore(axes, coordinates, cs, cellList);
      }

      if (level > 0) {
        coordinates.remove(level - 1);
      }

    } else {
      Position[] positions = new Position[coordinates.size()];
      positions = coordinates.toArray(positions);
      Cell cell = cs.getCell(positions);
      OlapCell olapCell = new OlapCell(positions, cell.getValue());
      cellList.add(olapCell);
      // System.out.println((++count) + " " + olapCell.toString());
      coordinates.remove(level - 1);
    }
  }
Example #15
0
 public CellSet followLine(Cell cell, Cell blocked) {
   CellSet nextCells = followLine(cell);
   if (nextCells.contains(blocked)) nextCells.remove(blocked);
   return nextCells;
 }