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++); } } } }
/** * Method to invoke when we encounter a block of text in the CSV file that is the contents of a * predicate variable. * * @param csvFile The csvFile we are currently parsing. * @param var The variable that we will be adding cells too. * @param arg The matrix template we are using when parsing individual matrix elements to put in * the spreadsheet. * @return The next line in the file that is not part of the block of text in the CSV file. * @throws IOException If unable to read the file correctly. */ private String parseMatrixVariable( final BufferedReader csvFile, final Variable var, final Argument arg) throws IOException { String line = csvFile.readLine(); while ((line != null) && Character.isDigit(line.charAt(0))) { // Split the line into tokens using a comma delimiter. String[] tokens = line.split(","); Cell newCell = var.createCell(); // Set the onset and offset from tokens in the line. newCell.setOnset(tokens[DATA_ONSET]); newCell.setOffset(tokens[DATA_OFFSET]); // Strip the brackets from the first and last argument. tokens[DATA_INDEX] = tokens[DATA_INDEX].substring(1, tokens[DATA_INDEX].length()); int end = tokens.length - 1; tokens[end] = tokens[end].substring(0, tokens[end].length() - 1); parseFormalArgs(tokens, DATA_INDEX, var.getVariableType(), (MatrixValue) newCell.getValue()); // Get the next line in the file for reading. line = csvFile.readLine(); } return line; }
@Test public void testCell() throws Exception { Cell c = new Cell(value, index, info); assertEquals(value, c.getValue()); assertEquals(Integer.MAX_VALUE, c.getCost()); assertEquals(null, c.getPrevious()); assertArrayEquals(neighbours, convertIntegers(c.getNeighbours())); }
@Override public boolean remove(@Nullable Object o) { if (o instanceof Cell) { Cell<?, ?, ?> cell = (Cell<?, ?, ?>) o; Map<C, V> row = Maps.safeGet(rowMap(), cell.getRowKey()); return row != null && Collections2.safeRemove( row.entrySet(), Maps.immutableEntry(cell.getColumnKey(), cell.getValue())); } return false; }
public Pack<T> call() { while (!this.canStop()) { this.crossOver(); this.mutation(); Collections.sort(this.population_); this.population_.subList(this.table_.size(), this.population_.size()).clear(); } Cell<T> survivor = this.population_.get(0); Pack<T> result = new Pack<T>(survivor.getValue(), new ArrayList<T>()); for (Entry<T, Boolean> e : survivor.getTable().entrySet()) { if (e.getValue()) { result.getItems().add(e.getKey()); } } return result; }
/** * Validates numbers in given sudoku group - numbers must be unique. Cells with invalid numbers * are marked (see {@link Cell#isValid}). * * <p>Method expects that cell's invalid properties has been set to false ({@link * CellCollection#validate} does this). * * @return True if validation is successful. */ protected boolean validate() { boolean valid = true; Map<Integer, Cell> cellsByValue = new HashMap<Integer, Cell>(); for (int i = 0; i < mCells.length; i++) { Cell cell = mCells[i]; int value = cell.getValue(); if (cellsByValue.get(value) != null) { mCells[i].setValid(false); cellsByValue.get(value).setValid(false); valid = false; } else { cellsByValue.put(value, cell); // we cannot set cell as valid here, because same cell can be invalid // as part of another group } } return valid; }
/** * Method to invoke when we encounter a block of text in the CSV file that is the contents of a * variable. * * @param csvFile The csvFile we are currently parsing. * @param var The variable that we will be adding cells too. * @param The populator to use when converting the contents of the cell into a datavalue that can * be inserted into the spreadsheet. * @return The next line in the file that is not part of the block of text in the CSV file. * @throws IOException If unable to read the file correctly. */ private String parseEntries( final BufferedReader csvFile, final Variable var, final EntryPopulator populator) throws IOException { // Keep parsing lines and putting them in the newly formed nominal // variable until we get to a line indicating the end of file or a new // variable section. String line = csvFile.readLine(); while ((line != null) && Character.isDigit(line.charAt(0))) { // Split the line into tokens using a comma delimiter. String[] tokens = line.split(","); // BugzID: 1075 - If the line ends with an escaped new line - add // the next line to the current text field. while ((line != null) && line.endsWith("\\") && !line.endsWith("\\\\")) { line = csvFile.readLine(); String content = tokens[tokens.length - 1]; content = content.substring(0, content.length() - 1); tokens[tokens.length - 1] = content + '\n' + line; } Cell newCell = var.createCell(); // Set the onset and offset from tokens in the line. newCell.setOnset(tokens[DATA_ONSET]); newCell.setOffset(tokens[DATA_OFFSET]); populator.populate(tokens, newCell.getValue()); // Get the next line in the file for reading. line = csvFile.readLine(); } return line; }
// 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); } }
/** Adds a captured cell to this player */ public void addCell(Cell c) { // Add what this cell is worth to this player'score this.Cells.add(c); this.score += c.getValue(); }
/** Adds a captured cell to this player */ public void removeCell(Cell c) { // Add what this cell is worth to this player'score this.Cells.remove(c); this.score -= c.getValue(); }
private Boolean canStop() { Cell<T> head = this.population_.get(0); Cell<T> tail = this.population_.get(this.population_.size() - 1); return head.getValue().equals(tail.getValue()); }