public ColumnFamily cloneMeShallow(boolean reversed) { return cloneMeShallow(getFactory(), reversed); }
public ColumnFamily trim(ColumnFamily cf, int trimTo, long now) { // each cell can increment the count by at most one, so if we have fewer cells than trimTo, we can skip trimming if (cf.getColumnCount() < trimTo) return cf; ColumnCounter counter = columnCounter(cf.getComparator(), now); ColumnFamily trimmedCf = cf.getFactory().create(cf.metadata(), reversed, trimTo); trimmedCf.delete(cf); Collection<Cell> cells = reversed ? cf.getReverseSortedColumns() : cf.getSortedColumns(); DeletionInfo.InOrderTester tester = cf.deletionInfo().inOrderTester(reversed); for (Iterator<Cell> iter = cells.iterator(); iter.hasNext(); ) { Cell cell = iter.next(); counter.count(cell, tester); if (counter.live() > trimTo) { break; } else { trimmedCf.addColumn(cell); } } return trimmedCf; }
private ColumnFamily scored(Float score, ColumnFamily data) { ColumnFamily cleanColumnFamily = data.getFactory().create(table.metadata); String indexColumnName = resultMapper.tableMapper.primaryColumnName(); boolean metaColReplaced = false; Cell firstColumn = null; for (Cell column : data) { if (firstColumn == null) firstColumn = column; ColumnIdentifier cellName = column.name().cql3ColumnName(table.metadata); String thisColName = cellName.toString(); boolean isIndexColumn = indexColumnName.equals(thisColName); if (isIndexColumn) { Cell scoreColumn = new BufferCell(column.name(), UTF8Type.instance.decompose("{\"score\":" + score.toString() + "}")); cleanColumnFamily.addColumn(scoreColumn); metaColReplaced = true; } else { cleanColumnFamily.addColumn(column); } } if (!metaColReplaced && firstColumn != null) { Cell newColumn = getMetaColumn(firstColumn, score); cleanColumnFamily.addColumn(newColumn); } return cleanColumnFamily; }