예제 #1
0
파일: Test.java 프로젝트: dingding2014/olap
  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++);
        }
      }
    }
  }
예제 #2
0
 public boolean isBullet(Cell cell) {
   char c = get(cell);
   return (c == 'o' || c == '*')
       && isBlank(cell.getEast())
       && isBlank(cell.getWest())
       && Character.isLetterOrDigit(get(cell.getEast().getEast()));
 }
예제 #3
0
  /**
   * Provides the ability to insert a new Score entity.
   *
   * @param board object representing the state of the board
   * @return the board including the computer's move
   */
  @ApiMethod(name = "board.getmove", path = "getmove", httpMethod = "POST")
  public Board getmove(
      Board board, @Named("id") int id, @Named("row") int row, @Named("col") int col) {
    System.out.println("id: " + id);

    CellContainer cellContainer = CellContainer.fromJson(board.getState());
    ArrayList<Cell> cells = cellContainer.cells;

    ArrayList<Cell> unoccupiedCells = new ArrayList<Cell>();
    for (Cell cell : cells) {
      System.out.println("row: " + row + " | cell.x: " + cell.x);
      if (row == cell.x && col == cell.y && row != 100 && col != 100) {
        System.out.println("updated 1");
        cell.val += (id + 1) * 10;
        CellContainer updateContainer = new CellContainer(cells);
        Board updated = new Board(CellContainer.toJson(updateContainer));
        return updated;
      }

      if (cell.val <= 10) {
        unoccupiedCells.add(cell);
      }
    }

    if (id == 0) System.out.println("what");
    Random randomG = new Random();
    System.out.println("updated 2");
    Cell randomfreeCell = unoccupiedCells.get(randomG.nextInt(unoccupiedCells.size()));
    randomfreeCell.val = randomfreeCell.val + (id + 1) * 10;

    CellContainer updateContainer = new CellContainer(cells);
    Board updated = new Board(CellContainer.toJson(updateContainer));
    return updated;
  }
예제 #4
0
  public void replacePointMarkersOnLine() {
    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);
        Cell cell = new Cell(xi, yi);
        if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(cell)) {

          boolean isOnHorizontalLine = false;
          if (StringUtils.isOneOf(get(cell.getEast()), horizontalLines)) isOnHorizontalLine = true;
          if (StringUtils.isOneOf(get(cell.getWest()), horizontalLines)) isOnHorizontalLine = true;

          boolean isOnVerticalLine = false;
          if (StringUtils.isOneOf(get(cell.getNorth()), verticalLines)) isOnVerticalLine = true;
          if (StringUtils.isOneOf(get(cell.getSouth()), verticalLines)) isOnVerticalLine = true;

          if (isOnHorizontalLine && isOnVerticalLine) {
            set(xi, yi, '+');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with +");
          } else if (isOnHorizontalLine) {
            set(xi, yi, '-');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with -");
          } else if (isOnVerticalLine) {
            set(xi, yi, '|');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with |");
          }
        }
      }
    }
  }
예제 #5
0
 static void joinGroup(long groupId1, long groupId2, Cell[] row) {
   for (Cell cell : row) {
     if (cell.groupId == groupId2) {
       cell.groupId = groupId1;
     }
   }
 }
예제 #6
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;
 }
예제 #7
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;
  }
예제 #8
0
파일: MetaK.java 프로젝트: TomGebhardt/k
 public static Term wrap(Term t, String label, Ellipses ellipses) {
   Cell cell = new Cell(t.getLocation(), t.getFilename());
   cell.setLabel(label);
   cell.setEllipses(ellipses);
   cell.setContents(t);
   return cell;
 }
예제 #9
0
 private Object getNumericCellValue(final Cell cell) {
   Object cellValue;
   if (DateUtil.isCellDateFormatted(cell)) {
     cellValue = new Date(cell.getDateCellValue().getTime());
   } else {
     cellValue = cell.getNumericCellValue();
   }
   return cellValue;
 }
예제 #10
0
 private int firstEmptyCellPosition(final Row cells) {
   int columnCount = 0;
   for (Cell cell : cells) {
     if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
       break;
     }
     columnCount++;
   }
   return columnCount;
 }
예제 #11
0
 @Override
 public void writeHeader() {
   if (header != null) {
     Row record = sheet.createRow(0);
     for (int i = 0; i < header.size(); i++) {
       Cell cell = record.createCell(i);
       cell.setCellValue(header.get(i));
     }
   }
 }
예제 #12
0
 public int otherStringsEndInTheSameColumn(Cell cell) {
   if (!isStringsEnd(cell)) return 0;
   int result = 0;
   int height = getHeight();
   for (int y = 0; y < height; y++) {
     Cell cCell = new Cell(cell.x, y);
     if (!cCell.equals(cell) && isStringsEnd(cCell)) {
       result++;
     }
   }
   return result;
 }
예제 #13
0
 public void removeColorCodes() {
   for (CellColorPair o : findColorCodes()) {
     Cell cell = o.cell;
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
     cell = cell.getEast();
     set(cell, ' ');
   }
 }
예제 #14
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;
 }
예제 #15
0
  private void countJars() {

    for (Cell c : cells) {
      c.resetObjIterator();

      while (c.objectIterator().hasNext()) {
        if (c.objectIterator().next() instanceof Jar) {
          jarCounter++;
        }
      }
    }
  }
예제 #16
0
 public void replaceBullets() {
   int width = getWidth();
   int height = getHeight();
   for (int yi = 0; yi < height; yi++) {
     for (int xi = 0; xi < width; xi++) {
       Cell cell = new Cell(xi, yi);
       if (isBullet(cell)) {
         set(cell, ' ');
         set(cell.getEast(), '\u2022');
       }
     }
   }
 }
예제 #17
0
  void tryCreateWall(Cell cell1, Cell cell2, Cell[] row) {

    if (cell1.groupId != cell2.groupId) {
      if (random.nextBoolean()) {
        cell1.right = true;
      } else {
        long tmpId = cell2.groupId;
        joinGroup(cell1.groupId, tmpId, row);
      }
    } else {
      cell1.right = true;
    }
  }
예제 #18
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;
 }
예제 #19
0
    /** Presents the given cell feed as a map from row, column pair to CellEntry. */
    private void refreshCachedData() throws IOException, ServiceException {

      CellQuery cellQuery = new CellQuery(backingEntry.getCellFeedUrl());
      cellQuery.setReturnEmpty(true);
      this.cellFeed = spreadsheetService.getFeed(cellQuery, CellFeed.class);

      //            A subtlety: Spreadsheets row,col numbers are 1-based whereas the
      //            cellEntries array is 0-based. Rather than wasting an extra row and
      //            column worth of cells in memory, we adjust accesses by subtracting
      //            1 from each row or column number.
      cellEntries = new CellEntry[rows][columns];
      for (CellEntry cellEntry : cellFeed.getEntries()) {
        Cell cell = cellEntry.getCell();
        cellEntries[cell.getRow() - 1][cell.getCol() - 1] = cellEntry;
      }
    }
예제 #20
0
  public static ArrayList<Cell> findPath(Cell start, Cell goal, Map<String, Cell> gridCells) {
    Set<Cell> closedSet = new HashSet<>();
    Set<Cell> openSet = new HashSet<>();
    openSet.add(start);
    start.g = 0;
    start.h = heuristicCostEstimate(start, goal);
    start.f = start.g + start.h;

    while (!openSet.isEmpty()) {
      double min = Integer.MAX_VALUE;
      Cell x = null;
      for (Cell cell : openSet)
        if (cell.f < min) {
          x = cell;
          min = cell.f;
        }
      if (goal.equals(x)) return reconstructPath(start, goal);
      openSet.remove(x);
      closedSet.add(x);
      for (Cell y : neighborNodes(x, gridCells)) {
        if (closedSet.contains(y)) continue;
        boolean tentativeIsBetter;
        // <tentative>
        double tentativeG = x.g + 2;
        if (x.cameFrom != null) {
          if (x.cameFrom.cameFrom != null
              && Math.abs(x.cameFrom.cameFrom.x - y.x) + Math.abs(x.cameFrom.cameFrom.y - y.y)
                  == 1) {
            tentativeG += 2;
          }
          if (x.cameFrom.y == x.y && y.y != x.y || x.cameFrom.x == x.x && y.x != x.x) {
            tentativeG += (2 * Math.sqrt(2) - 4);
          }
        }
        if (y.isPenult) tentativeG += 10;
        // </tentative>
        if (!openSet.contains(y)) {
          openSet.add(y);
          tentativeIsBetter = true;
        } else {
          tentativeIsBetter = tentativeG < y.g;
        }
        if (tentativeIsBetter) {
          y.cameFrom = x;
          y.g = tentativeG;
          y.h = heuristicCostEstimate(y, goal);
          y.f = y.g + y.h;
        }
      }
    }
    return new ArrayList<>();
  }
예제 #21
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;
 }
예제 #22
0
  public boolean allJarsOnMarks() {

    int jars = 0;
    GameObject obj;

    for (Cell c : cells) {
      c.resetObjIterator();

      while (c.objectIterator().hasNext()) {
        if ((obj = c.objectIterator().next()) instanceof Mark) {
          jars += ((Mark) obj).getJarCounter();
        }
      }
    }

    if (jars >= jarCounter) {
      return true;
    }
    return false;
  }
예제 #23
0
  private void loadMap() {
    char ch;
    CellBuilder cb = new CellBuilder();
    String mapLine;
    Loader.loadMap();

    while ((mapLine = Loader.loadLine()) != null) {

      cols = mapLine.length();

      for (int i = 0; i < cols; i++) {

        Cell nextCell = cb.nextCell();
        cells.add(nextCell);
        nextCell.draw();

        if ((ch = mapLine.charAt(i)) != '_') {
          if (ch == 'r') {
            if (robotPosition != null) {
              System.out.println("You may only create one robot. A robot was discarded");
            } else {
              robotPosition = new Position(i % cols, rows, this);
            }
          } else {

            try {
              GameObject obj =
                  new ObjectBuilder().setPos(nextCell.getPos()).setType(ch).createObject();
              nextCell.addObject(obj);
            } catch (Exception e) {
              System.out.println("No object found for this symbol -> " + ch + ". Discarded");
            }
          }
        }
        nextCell.drawObjects();
      }

      cb.nextRow();
      rows++;
    }
  }
예제 #24
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;
 }
예제 #25
0
  @Override
  public Point[] findPath(Maze maze) {
    cols = maze.cols;
    rows = maze.rows;
    Cell[][] cells = new Cell[maze.rows][maze.cols];
    Set<Cell> cellSet = new HashSet<>();
    for (int y = 0; y < maze.rows; y++) {
      for (int x = 0; x < maze.cols; x++) {
        Cell cell = new Cell(x, y, maze.data[x][y]);
        cells[x][y] = cell;
        cellSet.add(cell);
      }
    }

    Cell start = cells[0][0];
    start.distance = 0;
    Cell finish = cells[rows - 1][cols - 1];
    int wave = 0;
    do {
      for (Cell cell : cellSet) {
        if (cell.distance == wave) {
          List<Cell> neighbors = cell.getNeighborCells(cellSet);
          for (Cell neighbor : neighbors) {
            if (neighbor.distance == -1) {
              neighbor.distance = wave + 1;
            }
          }
        }
      }
      wave++;
    } while (finish.distance == -1);
    List<Cell> path = new ArrayList<>();
    path.add(finish);
    Cell currCell = finish;
    while (!path.contains(start)) {
      assert currCell != null;
      currCell = getСlosest(currCell.getNeighborCells(cellSet));
      path.add(currCell);
    }
    logger.debug("Построен путь от входа к выходу длиной {}", wave);

    Point[] pathPoints = new Point[path.size()];
    for (int i = 0; i < pathPoints.length; i++) {
      pathPoints[i] = new Point(path.get(i).x, path.get(i).y);
    }

    return pathPoints;
  }
예제 #26
0
  @Override
  public Point[] findPath(Maze maze) {
    cols = maze.cols;
    rows = maze.rows;
    Cell[][] cells = new Cell[maze.rows][maze.cols];
    Set<Cell> cellSet = new HashSet<>();
    for (int j = 0; j < maze.rows; j++) {
      for (int i = 0; i < maze.cols; i++) {
        Cell cell = new Cell(i, j, maze.data[i][j]);
        cells[j][i] = cell;
        cellSet.add(cell);
      }
    }

    Cell start = cells[0][0];
    start.distance = 0;
    Cell finish = cells[rows - 1][cols - 1];
    int wave = 0;
    do {
      for (Cell cell : cellSet) {
        if (cell.distance == wave) {
          List<Cell> neighbors = cell.getNeighbors(cellSet);
          for (Cell neighbor : neighbors) {
            if (neighbor.distance == -1) {
              neighbor.distance = wave + 1;
            }
          }
        }
      }
      wave++;
    } while (finish.distance == -1);
    List<Cell> path = new ArrayList<>();
    path.add(finish);
    Cell currCell = finish;
    while (!path.contains(start)) {
      assert currCell != null;
      currCell = getNearest(currCell.getNeighbors(cellSet));
      path.add(currCell);
    }
    logger.debug("найден путь от выхода до входа, его длинна {}", wave);

    Point[] pathPoints = new Point[path.size()];
    for (int i = 0; i < pathPoints.length; i++) {
      pathPoints[i] = new Point(path.get(i).x, path.get(i).y);
    }
    logger.debug("обратный путь построен");
    return pathPoints;
  }
예제 #27
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;
  }
예제 #28
0
 void tryCreateFloor(Cell cell, Cell[] row) {
   int cellsWithFloor = 0;
   int cellsInGroup = 0;
   for (Cell cellFromRow : row) {
     if (cellFromRow.groupId == cell.groupId) {
       cellsInGroup++;
       if (cellFromRow.down) {
         cellsWithFloor++;
       }
     }
   }
   if (cellsInGroup > cellsWithFloor + 1) {
     cell.down = random.nextBoolean();
   }
 }
  protected org.zkoss.poi.ss.usermodel.Font getPoiFontFromRichText(
      Workbook book, Cell cell, RichTextString rstr, int run) {
    if (run < 0) return null; // ZSS-1138

    org.zkoss.poi.ss.usermodel.Font font =
        rstr instanceof HSSFRichTextString
            ? book.getFontAt(((HSSFRichTextString) rstr).getFontOfFormattingRun(run))
            : ((XSSFRichTextString) rstr).getFontOfFormattingRun((XSSFWorkbook) book, run);
    if (font == null) {
      CellStyle style = cell.getCellStyle();
      short fontIndex = style != null ? style.getFontIndex() : (short) 0;
      return book.getFontAt(fontIndex);
    }
    return font;
  }
예제 #30
0
파일: Test.java 프로젝트: dingding2014/olap
  // 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);
    }
  }