List of usage examples for java.util TreeSet tailSet
public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
From source file:Main.java
public static void main(String[] args) { TreeSet<Integer> treeadd = new TreeSet<Integer>(); treeadd.add(1);/*from ww w . j ava 2 s .co m*/ treeadd.add(2); treeadd.add(3); treeadd.add(4); treeadd.add(5); treeadd.add(6); treeadd.add(7); treeadd.add(8); TreeSet<Integer> treetailsetincl = (TreeSet<Integer>) treeadd.tailSet(5, true); Iterator<Integer> iterator = treetailsetincl.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next()); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.DAMQueriesLevel2.java
/** * Combines all the level2DataFiles (getConstituentDataFiles()) into one file * @param dataFile/*from w ww . j a v a 2 s . co m*/ * @throws IOException */ public void createConsolidatedFiles(final DataFile dataFile) throws IOException { DiseaseContextHolder.setDisease(dataFile.getDiseaseType()); if (tempfileDirectory == null) { throw new IOException("No tempfileDirectory specified"); } if (!(new File(tempfileDirectory)).exists()) { throw new IOException("Directory does not exist " + tempfileDirectory); } final DataFileLevelTwoConsolidated dataFileLevelTwoConsolidated = (DataFileLevelTwoConsolidated) dataFile; final String uniqueName = getUniqueFilename(dataFileLevelTwoConsolidated); final String consolidatedFilePath = tempfileDirectory + File.separator + uniqueName; final String consolidatedTmpFilePath = consolidatedFilePath + "_tmp"; dataFileLevelTwoConsolidated.setPath(consolidatedFilePath); TreeSet<DataFileLevelTwo> dataFilesLevelTwo = dataFileLevelTwoConsolidated.getConstituentDataFiles(); // copy first file into consolidatedFile FileUtil.copyFile(dataFilesLevelTwo.first().getPath(), consolidatedFilePath); // copy other files into consolidated file final StringBuilder dataToWrite = new StringBuilder(); for (DataFileLevelTwo dataFileLevelTwo : dataFilesLevelTwo.tailSet(dataFilesLevelTwo.first(), false)) { BufferedReader consolidatedFile = null; BufferedReader constituentFile = null; BufferedWriter consolidatedTmpFile = null; try { consolidatedFile = new BufferedReader(new FileReader(consolidatedFilePath), SIXTY_FOUR_MEGS); constituentFile = new BufferedReader(new FileReader(dataFileLevelTwo.getPath()), SIXTY_FOUR_MEGS); consolidatedTmpFile = new BufferedWriter(new FileWriter(consolidatedTmpFilePath), SIXTY_FOUR_MEGS); String constituentRowData = ""; boolean firstRow = true; int numColumnsToSkip = 1; // default, but will change if file has constant columns // assuming all the files will have same row count while ((constituentRowData = constituentFile.readLine()) != null) { // clear the data dataToWrite.delete(0, dataToWrite.length()); final String consolidatedRowData = consolidatedFile.readLine(); if (consolidatedRowData != null) { final String[] rowDataArray = constituentRowData.split("\\t"); if (firstRow) { for (final String cellData : rowDataArray) { if (cellData.length() == 0) { numColumnsToSkip++; } } } else { dataToWrite.append("\n"); } dataToWrite.append(consolidatedRowData); for (int i = numColumnsToSkip; i < rowDataArray.length; i++) { dataToWrite.append("\t").append(rowDataArray[i]); } consolidatedTmpFile.write(dataToWrite.toString()); } firstRow = false; } } finally { closeFile(consolidatedFile); closeFile(constituentFile); closeFile(consolidatedTmpFile); // move consolidatedTmpFile to consolidatedFile FileUtil.move(consolidatedTmpFilePath, consolidatedFilePath); new File(consolidatedTmpFilePath).delete(); } } }