Exemplo n.º 1
0
 @Override
 public void visit(CellCollection cellCollection) {
   for (Cell cell : cellCollection.cells()) {
     cell.accept(this);
   }
   visit((Collection) cellCollection);
 }
Exemplo n.º 2
0
 public Range(Sheet sheet, Cell cell) {
   this.sheet = sheet;
   fromColumn = cell.getColumn();
   fromRow = cell.getRow();
   toColumn = cell.getColumn();
   toRow = cell.getRow();
 }
Exemplo n.º 3
0
 public Tile getCellContent(Cell cell) {
   if (cell != null && isCellWithinBounds(cell)) {
     return field[cell.getX()][cell.getY()];
   } else {
     return null;
   }
 }
Exemplo n.º 4
0
 @Override
 public String toString() {
   if (isEmpty()) {
     return DataStructureSort.LABELS.get(org.kframework.kil.Sort.BAG).get(Label.UNIT);
   } else {
     StringBuilder stringBuilder = new StringBuilder();
     for (Cell cell : cells.values()) {
       stringBuilder
           .append("<")
           .append(cell.cellLabel())
           .append(">")
           .append(cell.content())
           .append("</")
           .append(cell.cellLabel())
           .append(">");
     }
     Iterator<Term> iter = baseTerms().iterator();
     while (iter.hasNext()) {
       stringBuilder.append(iter.next());
       if (iter.hasNext()) {
         stringBuilder.append(" ");
       }
     }
     return stringBuilder.toString();
   }
 }
Exemplo n.º 5
0
  public boolean remove(WorldObject obj) {
    Cell c = getCell(obj.getPoint().x, obj.getPoint().y);
    if (c.area.contains(obj.getPoint())) {
      if (c.elements.remove(obj)) {
        size--;
        return true;
      }
    } else {

      c = getCell(obj.oldPos.x, obj.oldPos.y);
      if (!c.elements.remove(obj)) {
        System.err.println(obj.toString() + "wasn't in cell" + c.loc() + " checking all cells.");
      } else {
        return true;
      }

      boolean removed = false;
      for (int x = 0; x < xSteps; x++) {
        for (int y = 0; y < ySteps; y++) {
          if (cells[x][y].elements.remove(obj)) {
            System.err.println(
                obj.toString() + "was found in cell" + cells[x][y].loc() + " removed.");
            removed = true;
            size--;
          }
        }
      }
      return removed;
    }
    System.err.println(obj.toString() + " wasn't in the grid. Loc: " + obj.getPoint().toString());
    return false;
  }
Exemplo n.º 6
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 |");
          }
        }
      }
    }
  }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 public void emptyAllCells() {
   for (Cell[] cellArr : this.cells) {
     for (Cell a : cellArr) {
       a.setMark(PlayerMark.EMPTY);
     }
   }
 }
Exemplo n.º 9
0
  public void paintComponent(Graphics g) throws RuntimeException {
    int squarewidth = getSquareWidth();
    int squareheight = getSquareHeight();

    int hoffset = getHorizontalOffset();
    int voffset = getVerticalOffset();

    for (int x = 0; x < grid.maxX(); x++) {
      for (int y = 0; y < grid.maxY(); y++) {
        Cell tmp = grid.grabObjectAt(x, y);

        if (tmp == null) {
          g.setColor(Color.gray.darker());
        } else {
          g.setColor(tmp.getColor());
        }

        g.fillRect(
            hoffset + x * squarewidth,
            voffset + ((grid.maxY() - y) * squareheight),
            squarewidth - 1,
            squareheight - 1);
      }
    }
  }
Exemplo n.º 10
0
  public void add(String type) {
    log.info("addRow");
    Cell cell1 = new Cell();
    cell1.setValue(0);

    Coll coll1 = new Coll();
    coll1.setIndex(0);
    coll1.setCell(cell1);

    ArrayList<Coll> aColl = new ArrayList<Coll>();
    aColl.add(coll1);

    Row row1 = new Row();
    row1.setIndex(0);
    row1.setColl(aColl);

    ArrayList<Row> aRow = new ArrayList<Row>();
    aRow.add(row1);

    Function f = new Function();
    f.setRow(aRow);
    f.setDescription("newFunction");
    f.setNameFirstArgument("x");
    f.setName("y");
    f.setType(type);
    getFunctions().add(f);
  }
Exemplo n.º 11
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++);
        }
      }
    }
  }
Exemplo n.º 12
0
  /**
   * Helper method of moved method.
   *
   * @param c receives array of adjacent cells.
   * @return Returns the cell where the herbivore will be move.
   */
  private Cell adjPlants(ArrayList<Cell> c) {

    Cell tempCell = null;
    ArrayList<Cell> emptyCells = new ArrayList<>();

    for (Cell fCells : c) {
      if (fCells.getComponentCount() > 0) {
        if (fCells.getComponents()[0] instanceof Plant) {

          // set life back to 5 (since herbivore had eaten)
          temp.life = 5;

          tempCell = fCells;

          return tempCell;
        }
      }
    }
    /*get a random adjacent cell if plants are not around
     * two herbivores cannot be in a same spot.
     */
    for (Cell fCells : c) {
      if (fCells.getComponentCount() == 0) {

        emptyCells.add(fCells);
      }
    }

    tempCell = emptyCells.get(RandomGenerator.nextNumber(emptyCells.size() - 1));

    return tempCell;
  }
Exemplo n.º 13
0
  @Test
  public void shouldTrueOnIsNeighborCheckIfTheCellsAreHorizontallyNextToEachOther() {
    Cell cellOne = new Cell(0, 1);
    Cell cellTwo = new Cell(0, 2);

    assertTrue(cellOne.isNeighbour(cellTwo));
  }
Exemplo n.º 14
0
  public void format() {

    wb = new XSSFWorkbook();

    Map styles = createStyles(wb);
    Sheet sheet = wb.createSheet("Loan Calculator");
    sheet.setPrintGridlines(false);
    sheet.setDisplayGridlines(false);
    PrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);
    sheet.setColumnWidth(0, 768);
    sheet.setColumnWidth(1, 768);
    sheet.setColumnWidth(2, 2816);
    sheet.setColumnWidth(3, 3584);
    sheet.setColumnWidth(4, 3584);
    sheet.setColumnWidth(5, 3584);
    sheet.setColumnWidth(6, 3584);

    Row titleRow = sheet.createRow(0);
    titleRow.setHeightInPoints(35F);
    for (int i = 1; i <= 7; i++)
      titleRow.createCell(i).setCellStyle((CellStyle) styles.get("title"));

    Cell titleCell = titleRow.getCell(2);
    titleCell.setCellValue("Simple");
  }
Exemplo n.º 15
0
 /** Switches the state of each cell in the grid to it's next state. */
 public void updateGrid() {
   for (List<Cell> list : myCells) {
     for (Cell cell : list) {
       cell.updateCell();
     }
   }
 }
Exemplo n.º 16
0
 @Override
 public T set(int index, T value) {
   Cell<T> c = find(index);
   T old = c.value;
   c.value = value;
   return old;
 }
    @Override
    public double calculateEnergyFlow( Cell cell, Cell neigh, int whichNeighbour )
    {
        double energy = super.calculateEnergyFlow( cell, neigh, whichNeighbour );
        // wymiana ciepla w powietrzu
        if( cell.get_material().get_name().equals( "Air" )
                && neigh.get_material().get_name().equals( "Air" ) )
        {
            energy *= EnvSettings.CONSTANT_ENERGY_FACTOR;

			if( whichNeighbour == EnvSettings.TOP_NEIGHBOUR )
            {
                energy *= TOP_ENERGY_FACTOR;

            if( ( whichNeighbour == EnvSettings.TOP_NEIGHBOUR && energy < 0 )
                    || ( whichNeighbour == EnvSettings.BOTTOM_NEIGBOUR && energy > 0 ) )
            {
                energy *= TOP_ENERGY_FACTOR;

            }
            else if( ( whichNeighbour == EnvSettings.BOTTOM_NEIGBOUR && energy < 0 )
                    || ( whichNeighbour == EnvSettings.TOP_NEIGHBOUR && energy > 0 ) )
            {
                energy *= DOWN_ENERGY_FACTOR;
            }
            else
            {
                energy *= SIDE_ENERGY_FACTOR;
            }
        }
        return energy;
    }
}
Exemplo n.º 18
0
  public int CreateFriendship(int friendid1, int friendid2) {
    // TODO Auto-generated method stub
    long mutator;
    try {
      mutator = client.mutator_open(namespace, ConfirmedFriendsTable, 0, 0);

      List<Cell> cells = new ArrayList<Cell>();
      Key key = null;
      Cell cell = null;

      key = new Key(friendid1 + "", ConfirmedFriendsTableCF[1], null, KeyFlag.INSERT);
      cell = new Cell(key);
      cell.setValue((friendid2 + "").getBytes("UTF-8"));
      cells.add(cell);

      key = new Key(friendid2 + "", ConfirmedFriendsTableCF[1], null, KeyFlag.INSERT);
      cell = new Cell(key);
      cell.setValue((friendid1 + "").getBytes("UTF-8"));
      cells.add(cell);

      client.mutator_set_cells(mutator, cells);
      client.mutator_flush(mutator);
      cells.clear();

    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
    return 0;
  }
Exemplo n.º 19
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()));
 }
Exemplo n.º 20
0
  public int insertEntity(
      String entitySet,
      String entityPK,
      HashMap<String, ByteIterator> values,
      boolean insertImage) {
    // TODO Auto-generated method stub
    /* Insert into table */
    try {
      long mutator = client.mutator_open(namespace, entitySet, 0, 0);
      List<Cell> cells = new ArrayList<Cell>();
      Key key = null;
      Cell cell = null;

      for (HashMap.Entry<String, ByteIterator> entry : values.entrySet()) {
        key = new Key(entityPK, entry.getKey(), null, KeyFlag.INSERT);
        cell = new Cell(key);
        cell.setValue(entry.getValue().toArray());
        cells.add(cell);
      }

      client.mutator_set_cells(mutator, cells);
      client.mutator_flush(mutator);
      cells.clear();
      client.mutator_close(mutator);
    } catch (ClientException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
    return 0;
  }
Exemplo n.º 21
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;
  }
Exemplo n.º 22
0
 public ArrayList<String> print() {
   ArrayList<String> result = new ArrayList<>();
   for (Cell c : cells) {
     result.add(c.getPossibilities());
   }
   return result;
 }
Exemplo n.º 23
0
 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;
 }
Exemplo n.º 24
0
  public static boolean isValid(GardenModel mod) {
    for (Garden g : mod.gardens) {
      if (g.getTreeCount() > mod.trees) return false;
      if (g.getUnknownCount() + g.getTreeCount() < mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateColumns(); it.hasNext(); ) {
      Line col = it.next();
      if (col.getTreeCount() > mod.trees) return false;
      if (col.getUnknownCount() + col.getTreeCount() < mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateRows(); it.hasNext(); ) {
      Line row = it.next();
      if (row.getTreeCount() > mod.trees) return false;
      if (row.getUnknownCount() + row.getTreeCount() < mod.trees) return false;
    }

    for (Cell c : mod.grid) {
      if (c.getState() == State.Tree) {
        for (Iterator<Cell> it = mod.grid.iterateAdjacent(c); it.hasNext(); ) {
          if (it.next().getState() == State.Tree) return false;
        }
      }
    }

    for (Garden g : mod.gardens) {
      if (!g.areThereEnoughFreeNonAdjacentCells()) return false;
    }
    for (Line l : mod.grid.getColumnsAndRows()) {
      if (!l.areThereEnoughFreeNonAdjacentCells(mod.trees)) return false;
    }

    return checkBalance(mod);
  }
  public void parseData(
      final Sheet sheet,
      final int startRow,
      final int endColumn,
      final List<String> propertyNames,
      final Class clazzOfTestCase) {

    int rowCounter = startRow;

    while (!isBlank(sheet, rowCounter, endColumn)) {
      Row row = sheet.getRow(rowCounter - 1);
      for (int i = 0; i < endColumn; i++) {
        Cell cell = row.getCell(i);
        if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
          try {
            Method method = clazzOfTestCase.getMethod("set" + propertyNames.get(i), Object.class);
          } catch (NoSuchMethodException e) {
            e
                .printStackTrace(); // To change body of catch statement use File | Settings | File
                                    // Templates.
          }
        }
      }
    }
  }
Exemplo n.º 26
0
 @Override
 public void onClick(View arg0) {
   // TODO Auto-generated method stub
   if (((Cell) arg0).getSelectVal()) ((Cell) arg0).setBackgroundColor(Color.RED);
   else ((Cell) arg0).setBackgroundColor(Color.YELLOW);
   ((Cell) arg0).setSelectVal();
 }
Exemplo n.º 27
0
  public void createCircularField(Map map, Vector2D centerPosition, int terrainType, int size) {
    if (size < 1) return;

    int TILE_SIZE = 32;
    float halfATile = TILE_SIZE / 2;
    // convert to absolute pixel coordinates
    Vector2D asPixelsCentered =
        map.getCellCoordinatesInAbsolutePixels(
                centerPosition.getXAsInt(), centerPosition.getYAsInt())
            .add(Vector2D.create(halfATile, halfATile));

    double centerX = asPixelsCentered.getX();
    double centerY = asPixelsCentered.getY();

    for (int rangeStep = 0; rangeStep < size; rangeStep++) { // range 'steps'

      for (int degrees = 0; degrees < 360; degrees++) {

        // calculate as if we would draw a circle and remember the coordinates
        float rangeInPixels = (rangeStep * TILE_SIZE);
        double circleX = (centerX + (Trigonometry.cos[degrees] * rangeInPixels));
        double circleY = (centerY + (Trigonometry.sin[degrees] * rangeInPixels));

        // convert back the pixel coordinates back to a cell
        Cell cell =
            map.getCellByAbsoluteMapCoordinates(
                Coordinate.create((int) Math.ceil(circleX), (int) Math.ceil(circleY)));

        putTerrainOnCell(map, cell.getX(), cell.getY(), terrainType);
      }
    }
  }
Exemplo n.º 28
0
 CellInfo _getCellInfo() {
   CellInfo info = new CellInfo();
   info.setCellName(getCellName());
   info.setDomainName(getCellDomainName());
   info.setCellType(getCellType());
   info.setCreationTime(_creationTime);
   try {
     info.setCellVersion(_cell.getCellVersion());
   } catch (Exception e) {
   }
   try {
     info.setPrivateInfo(_cell.getInfo());
   } catch (Exception e) {
     info.setPrivateInfo("Not yet/No more available\n");
   }
   try {
     info.setShortInfo(_cell.toString());
   } catch (Exception e) {
     info.setShortInfo("Not yet/No more available");
   }
   info.setCellClass(_cellClass);
   try {
     info.setEventQueueSize(getEventQueueSize());
     info.setState(_state);
     info.setThreadCount(_threads.activeCount());
   } catch (Exception e) {
     info.setEventQueueSize(0);
     info.setState(0);
     info.setThreadCount(0);
   }
   return info;
 }
Exemplo n.º 29
0
 /** Test rendering the cell with a null value and no view data. */
 public void testRenderNull() {
   Cell<T> cell = createCell();
   SafeHtmlBuilder sb = new SafeHtmlBuilder();
   Context context = new Context(0, 0, null);
   cell.render(context, null, sb);
   assertEquals(getExpectedInnerHtmlNull(), sb.toSafeHtml().asString());
 }
  @Test
  public void rotatedText() throws Exception {
    Workbook workbook = _testDataProvider.createWorkbook();
    fixFonts(workbook);
    Sheet sheet = workbook.createSheet();
    Row row = sheet.createRow(0);

    CellStyle style1 = workbook.createCellStyle();
    style1.setRotation((short) 90);

    Cell cell0 = row.createCell(0);
    cell0.setCellValue("Apache Software Foundation");
    cell0.setCellStyle(style1);

    Cell cell1 = row.createCell(1);
    cell1.setCellValue("Apache Software Foundation");

    for (int i = 0; i < 2; i++) sheet.autoSizeColumn(i);

    int w0 = sheet.getColumnWidth(0);
    int w1 = sheet.getColumnWidth(1);

    assertTrue(
        w0 * 5 < w1); // rotated text occupies at least five times less horizontal space than normal
    // text

    workbook.close();
  }