List of usage examples for java.util List removeAll
boolean removeAll(Collection<?> c);
From source file:Main.java
public static void main(String[] argv) throws Exception { List list1 = new ArrayList(); List list2 = new ArrayList(); list1.addAll(list2);/* w ww. java2 s . co m*/ list1.removeAll(list2); list1.retainAll(list2); list1.clear(); int newSize = 2; list1.subList(newSize, list1.size()).clear(); }
From source file:MainClass.java
public static void main(String args[]) { String init[] = { "One", "Two", "Three", "One", "Two", "Three" }; List list1 = new ArrayList(Arrays.asList(init)); List list2 = new ArrayList(Arrays.asList(init)); list1.remove("One"); System.out.println(list1);/*from w w w . j ava 2 s. c o m*/ list2.removeAll(Collections.singleton("One")); System.out.println(list2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List<String> list1 = new ArrayList(); List<String> list2 = new ArrayList(); list1.addAll(list2);//from w w w . j a v a 2 s .c o m list1.removeAll(list2); list1.retainAll(list2); list1.clear(); int newSize = 2; list1.subList(newSize, list1.size()).clear(); }
From source file:Main.java
public static void main(String args[]) { String init[] = { "One", "Two", "Three", "One", "Two", "Three" }; // create two lists List<String> list1 = new ArrayList<String>(Arrays.asList(init)); List<String> list2 = new ArrayList<String>(Arrays.asList(init)); // remove from list1 list1.remove("One"); System.out.println("List1 value: " + list1); // remove from list2 using singleton list2.removeAll(Collections.singleton("One")); System.out.println("The SingletonList is :" + list2); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { List list = new ArrayList(); list.add("A"); list.add("A"); list.add("B"); list.add("B"); list.add("C"); list.add("C"); List list2 = new ArrayList(); list2.add("A"); list2.add("B"); list2.add("C"); list.removeAll(list2); System.out.println(list);/*from w ww. j a v a2 s . co m*/ }
From source file:MainClass.java
public static void main(String args[]) throws Exception { List list = new ArrayList(); list.add("A"); list.add("A"); list.add("B"); list.add("B"); list.add("C"); list.add("C"); list.add("D"); List list2 = new ArrayList(); list2.add("A"); list2.add("B"); list2.add("C"); list.removeAll(list2); System.out.println(list);/*w w w . ja va 2s . co m*/ }
From source file:Main.java
public static void main(String args[]) throws Exception { List<String> list = new ArrayList<String>(); list.add("A"); list.add("A"); list.add("B"); list.add("B"); list.add("C"); list.add("C"); List<String> list2 = new ArrayList<String>(); list2.add("A"); list2.add("B"); list2.add("C"); list.removeAll(list2); System.out.println(list);// w w w . ja v a 2s . c o m }
From source file:com.sangupta.keepwalking.MergeRepo.java
/** * @param args//from ww w . j a v a2s .c o m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 3) { usage(); return; } final String previousRepo = args[0]; final String newerRepo = args[1]; final String mergedRepo = args[2]; final File previous = new File(previousRepo); final File newer = new File(newerRepo); final File merged = new File(mergedRepo); if (!(previous.exists() && previous.isDirectory())) { System.out.println("The previous version does not exists or is not a directory."); return; } if (!(newer.exists() && newer.isDirectory())) { System.out.println("The newer version does not exists or is not a directory."); return; } final IOFileFilter directoryFilter = FileFilterUtils.makeCVSAware(FileFilterUtils.makeSVNAware(null)); final Collection<File> olderFiles = FileUtils.listFiles(previous, TrueFileFilter.TRUE, directoryFilter); final Collection<File> newerFiles = FileUtils.listFiles(newer, TrueFileFilter.TRUE, directoryFilter); // build a list of unique paths System.out.println("Reading files from older version..."); List<String> olderPaths = new ArrayList<String>(); for (File oldFile : olderFiles) { olderPaths.add(getRelativePath(oldFile, previous)); } System.out.println("Reading files from newer version..."); List<String> newerPaths = new ArrayList<String>(); for (File newerFile : newerFiles) { newerPaths.add(getRelativePath(newerFile, newer)); } // find which files have been removed from Perforce depot List<String> filesRemoved = new ArrayList<String>(olderPaths); filesRemoved.removeAll(newerPaths); System.out.println("Files removed in newer version: " + filesRemoved.size()); for (String removed : filesRemoved) { System.out.print(" "); System.out.println(removed); } // find which files have been added in Perforce depot List<String> filesAdded = new ArrayList<String>(newerPaths); filesAdded.removeAll(olderPaths); System.out.println("Files added in newer version: " + filesAdded.size()); for (String added : filesAdded) { System.out.print(" "); System.out.println(added); } // find which files are common // now check if they have modified or not newerPaths.retainAll(olderPaths); List<String> modified = checkModifiedFiles(newerPaths, previous, newer); System.out.println("Files modified in newer version: " + modified.size()); for (String modify : modified) { System.out.print(" "); System.out.println(modify); } // clean any previous existence of merged repo System.out.println("Cleaning any previous merged repositories..."); if (merged.exists() && merged.isDirectory()) { FileUtils.deleteDirectory(merged); } System.out.println("Merging from newer to older repository..."); // copy the original SVN repo to merged FileUtils.copyDirectory(previous, merged); // now remove all files that need to be for (String removed : filesRemoved) { File toRemove = new File(merged, removed); toRemove.delete(); } // now add all files that are new in perforce for (String added : filesAdded) { File toAdd = new File(newer, added); File destination = new File(merged, added); FileUtils.copyFile(toAdd, destination); } // now over-write modified files for (String changed : modified) { File change = new File(newer, changed); File destination = new File(merged, changed); destination.delete(); FileUtils.copyFile(change, destination); } System.out.println("Done merging."); }
From source file:LinkedListTest.java
public static void main(String[] args) { List<String> a = new LinkedList<String>(); a.add("Amy"); a.add("Carl"); a.add("Erica"); List<String> b = new LinkedList<String>(); b.add("Bob"); b.add("Doug"); b.add("Frances"); b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator(); Iterator<String> bIter = b.iterator(); while (bIter.hasNext()) { if (aIter.hasNext()) aIter.next();//from w w w . java2 s .c o m aIter.add(bIter.next()); } System.out.println(a); // remove every second word from b bIter = b.iterator(); while (bIter.hasNext()) { bIter.next(); // skip one element if (bIter.hasNext()) { bIter.next(); // skip next element bIter.remove(); // remove that element } } System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a); }
From source file:diffhunter.DiffHunter.java
/** * @param args the command line arguments * @throws org.apache.commons.cli.ParseException * @throws java.io.IOException/* w ww . j a va2 s .co m*/ */ public static void main(String[] args) throws ParseException, IOException { //String test_ = Paths.get("J:\\VishalData\\additional\\", "Sasan" + "_BDB").toAbsolutePath().toString(); // TODO code application logic here /*args = new String[] { "-i", "-b", "J:\\VishalData\\additional\\Ptbp2_E18_5_cortex_CLIP_mm9_plus_strand_sorted.bed", "-r", "J:\\VishalData\\additional\\mouse_mm9.txt", "-o", "J:\\VishalData" };*/ /*args = new String[] { "-c", "-r", "J:\\VishalData\\additional\\mouse_mm9.txt", "-1", "J:\\VishalData\\Ptbp2_Adult_testis_CLIP_mm9_plus_strand_sorted_BDB", "-2", "J:\\VishalData\\Ptbp2_E18_5_cortex_CLIP_mm9_plus_strand_sorted_BDB", "-w", "200", "-s", "50", "-o", "J:\\VishalData" };*/ Options options = new Options(); // add t option options.addOption("i", "index", false, "Indexing BED files."); options.addOption("b", "bed", true, "bed file to be indexed"); options.addOption("o", "output", true, "Folder that the index/comparison file will be created."); options.addOption("r", "reference", true, "Reference annotation file to be used for indexing"); options.addOption("c", "compare", false, "Finding differences between two conditions"); options.addOption("1", "first", true, "First sample index location"); options.addOption("2", "second", true, "Second sample index location"); options.addOption("w", "window", true, "Length of window for identifying differences"); options.addOption("s", "sliding", true, "Length of sliding"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); boolean indexing = false; boolean comparing = false; //Indexing! if (cmd.hasOption("i")) { //if(cmd.hasOption("1")) //System.err.println("sasan"); //System.out.println("sasa"); indexing = true; } else if (cmd.hasOption("c")) { //System.err.println(""); comparing = true; } else { //System.err.println("Option is not deteced."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } //Indexing is selected // if (indexing == true) { //Since indexing is true. //User have to provide file for indexing. if (!(cmd.hasOption("o") || cmd.hasOption("r") || cmd.hasOption("b"))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } String bedfile_ = cmd.getOptionValue("b"); String reference_file = cmd.getOptionValue("r"); String folder_loc = cmd.getOptionValue("o"); String sample_name = FilenameUtils.getBaseName(bedfile_); try (Database B2 = BerkeleyDB_Box.Get_BerkeleyDB( Paths.get(folder_loc, sample_name + "_BDB").toAbsolutePath().toString(), true, sample_name)) { Indexer indexing_ = new Indexer(reference_file); indexing_.Make_Index(B2, bedfile_, Paths.get(folder_loc, sample_name + "_BDB").toAbsolutePath().toString()); B2.close(); } } else if (comparing == true) { if (!(cmd.hasOption("o") || cmd.hasOption("w") || cmd.hasOption("s") || cmd.hasOption("1") || cmd.hasOption("2"))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("diffhunter", options); return; } String folder_loc = cmd.getOptionValue("o"); int window_ = Integer.parseInt(cmd.getOptionValue("w")); //int window_=600; int slide_ = Integer.parseInt(cmd.getOptionValue("s")); String first = cmd.getOptionValue("1").replace("_BDB", ""); String second = cmd.getOptionValue("2").replace("_BDB", ""); String reference_file = cmd.getOptionValue("r"); //String folder_loc=cmd.getOptionValue("o"); String sample_name_first = FilenameUtils.getBaseName(first); String sample_name_second = FilenameUtils.getBaseName(second); Database B1 = BerkeleyDB_Box.Get_BerkeleyDB(first + "_BDB", false, sample_name_first); Database B2 = BerkeleyDB_Box.Get_BerkeleyDB(second + "_BDB", false, sample_name_second); List<String> first_condition_genes = Files .lines(Paths.get(first + "_BDB", sample_name_first + ".txt").toAbsolutePath()) .collect(Collectors.toList()); List<String> second_condition_genes = Files .lines(Paths.get(second + "_BDB", sample_name_second + ".txt").toAbsolutePath()) .collect(Collectors.toList()); System.out.println("First and second condition are loaded!!! "); List<String> intersection_ = new ArrayList<>(first_condition_genes); intersection_.retainAll(second_condition_genes); BufferedWriter output = new BufferedWriter( new FileWriter(Paths.get(folder_loc, "differences_" + window_ + "_s" + slide_ + "_c" + ".txt") .toAbsolutePath().toString(), false)); List<Result_Window> final_results = Collections.synchronizedList(new ArrayList<>()); Worker_New worker_class = new Worker_New(); worker_class.Read_Reference(reference_file); while (!intersection_.isEmpty()) { List<String> selected_genes = new ArrayList<>(); //if (intersection_.size()<=10000){selected_genes.addAll(intersection_.subList(0, intersection_.size()));} //else selected_genes.addAll(intersection_.subList(0, 10000)); if (intersection_.size() <= intersection_.size()) { selected_genes.addAll(intersection_.subList(0, intersection_.size())); } else { selected_genes.addAll(intersection_.subList(0, intersection_.size())); } intersection_.removeAll(selected_genes); //System.out.println("Intersection count is:"+intersection_.size()); //final List<Result_Window> resultssss_=new ArrayList<>(); IntStream.range(0, selected_genes.size()).parallel().forEach(i -> { System.out.println(selected_genes.get(i) + "\tprocessing......"); String gene_of_interest = selected_genes.get(i);//"ENSG00000142657|PGD";//intersection_.get(6);////"ENSG00000163395|IGFN1";//"ENSG00000270066|SCARNA2"; int start = worker_class.dic_genes.get(gene_of_interest).start_loc; int end = worker_class.dic_genes.get(gene_of_interest).end_loc; Map<Integer, Integer> first_ = Collections.EMPTY_MAP; try { first_ = BerkeleyDB_Box.Get_Coord_Read(B1, gene_of_interest); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(DiffHunter.class.getName()).log(Level.SEVERE, null, ex); } Map<Integer, Integer> second_ = Collections.EMPTY_MAP; try { second_ = BerkeleyDB_Box.Get_Coord_Read(B2, gene_of_interest); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(DiffHunter.class.getName()).log(Level.SEVERE, null, ex); } List<Window> top_windows_first = worker_class.Get_Top_Windows(window_, first_, slide_); List<Window> top_windows_second = worker_class.Get_Top_Windows(window_, second_, slide_); //System.out.println("passed for window peak call for gene \t"+selected_genes.get(i)); // System.out.println("top_window_first_Count\t"+top_windows_first.size()); // System.out.println("top_window_second_Count\t"+top_windows_second.size()); if (top_windows_first.isEmpty() && top_windows_second.isEmpty()) { return; } List<Result_Window> res_temp = new Worker_New().Get_Significant_Windows(gene_of_interest, start, end, top_windows_first, top_windows_second, second_, first_, sample_name_first, sample_name_second, 0.01); if (!res_temp.isEmpty()) { final_results.addAll(res_temp);//final_results.addAll(worker_class.Get_Significant_Windows(gene_of_interest, start, end, top_windows_first, top_windows_second, second_, first_, first_condition, second_condition, 0.01)); } //System.out.println(selected_genes.get(i)+"\tprocessed."); }); /*selected_genes.parallelStream().forEach(i -> { });*/ List<Double> pvals = new ArrayList<>(); for (int i = 0; i < final_results.size(); i++) { pvals.add(final_results.get(i).p_value); } List<Double> qvals = MultipleTestCorrection.benjaminiHochberg(pvals); System.out.println("Writing to file..."); output.append("Gene_Symbol\tContributing_Sample\tStart\tEnd\tOddsRatio\tp_Value\tFDR"); output.newLine(); for (int i = 0; i < final_results.size(); i++) { Result_Window item = final_results.get(i); output.append(item.associated_gene_symbol + "\t" + item.contributing_windows + "\t" + item.start_loc + "\t" + item.end_loc + "\t" + item.oddsratio_ + "\t" + item.p_value + "\t" + qvals.get(i)); //+ "\t" + item.average_other_readcount_cotributing + "\t" + item.average_other_readcount_cotributing + "\t" + item.average_window_readcount_non + "\t" + item.average_other_readcount_non); output.newLine(); } /* for (Result_Window item : final_results) { output.append(item.associated_gene_symbol + "\t" + item.contributing_windows + "\t" + item.start_loc + "\t" + item.end_loc + "\t" + item.oddsratio_ + "\t" + item.p_value); //+ "\t" + item.average_other_readcount_cotributing + "\t" + item.average_other_readcount_cotributing + "\t" + item.average_window_readcount_non + "\t" + item.average_other_readcount_non); output.newLine(); } */ final_results.clear(); } output.close(); } System.out.println("Done."); }