Source:
<code>void updateDeleteLatestVersionTimestamp(Cell cell, Get get, int count, int maxVersions, byte[] byteNow, List<Cell> deleteCells) throws IOException { <START> List<Cell> result = new ArrayList<>(); result.addAll(deleteCells); <END> Scan scan = new Scan(get); scan.setRaw(true); this.getScanner(scan).next(result); result.sort((cell1, cell2) -> { if(cell1.getTimestamp()>cell2.getTimestamp()){ return -1; } else if(cell1.getTimestamp()<cell2.getTimestamp()){ return 1; } else { if(CellUtil.isDelete(cell1)){ return -1; } else if (CellUtil.isDelete(cell2)){ return 1; } } return 0; }); List<Cell> cells = new ArrayList<>(); if (result.size() < count) { PrivateCellUtil.updateLatestStamp(cell, byteNow); cells.add(cell); deleteCells.addAll(cells); } else if (result.size() > count) { int currentVersion = 0; long latestCellTS = Long.MAX_VALUE; for(Cell getCell : result){ if(!(CellUtil.matchingFamily(getCell, cell) && CellUtil.matchingQualifier(getCell, cell))){ continue; } if(!PrivateCellUtil.isDeleteType(getCell) && getCell.getTimestamp()!=latestCellTS){ if (currentVersion >= maxVersions) { Cell tempCell = null; try { tempCell = PrivateCellUtil.deepClone(cell); } catch (CloneNotSupportedException e) { throw new IOException(e); } PrivateCellUtil.setTimestamp(tempCell, getCell.getTimestamp()); cells.add(tempCell); } else if (currentVersion == 0) { PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp()); cells.add(cell); } currentVersion++; } latestCellTS = getCell.getTimestamp(); } } else { Cell getCell = result.get(0); PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp()); cells.add(cell); } deleteCells.addAll(cells); }</code><technical_language>nit: wrap ArrayList constructor: new ArrayList<>(deleteCells);</technical_language>

Target:
private void updateDeleteLatestVersionTimestamp(Cell cell, Get get, int count, int maxVersions, byte[] byteNow, List<Cell> deleteCells) throws IOException { List<Cell> result = new ArrayList<>(deleteCells); Scan scan = new Scan(get); scan.setRaw(true); this.getScanner(scan).next(result); List<Cell> cells = new ArrayList<>(); if (result.size() < count) { PrivateCellUtil.updateLatestStamp(cell, byteNow); cells.add(cell); deleteCells.addAll(cells); } else if (result.size() > count) { int currentVersion = 0; long latestCellTS = Long.MAX_VALUE; result.sort((cell1, cell2) -> { if(cell1.getTimestamp()>cell2.getTimestamp()){ return -1; } else if(cell1.getTimestamp()<cell2.getTimestamp()){ return 1; } else { if(CellUtil.isDelete(cell1)){ return -1; } else if (CellUtil.isDelete(cell2)){ return 1; } } return 0; }); for(Cell getCell : result){ if(!(CellUtil.matchingFamily(getCell, cell) && CellUtil.matchingQualifier(getCell, cell))){ continue; } if(!PrivateCellUtil.isDeleteType(getCell) && getCell.getTimestamp()!=latestCellTS){ if (currentVersion >= maxVersions) { Cell tempCell = null; try { tempCell = PrivateCellUtil.deepClone(cell); } catch (CloneNotSupportedException e) { throw new IOException(e); } PrivateCellUtil.setTimestamp(tempCell, getCell.getTimestamp()); cells.add(tempCell); } else if (currentVersion == 0) { PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp()); cells.add(cell); } currentVersion++; } latestCellTS = getCell.getTimestamp(); } } else { Cell getCell = result.get(0); PrivateCellUtil.setTimestamp(cell, getCell.getTimestamp()); cells.add(cell); } deleteCells.addAll(cells); }