List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:Main.java
public static void main(String[] argv) throws Exception { Set set1 = new HashSet(); Set set2 = new HashSet(); set1.removeAll(set2); }
From source file:MainClass.java
public static void main(String args[]) { String orig[] = { "I", "P", "E", "G", "P" }; String act[] = { "P", "P", "S" }; Set origSet = new HashSet(Arrays.asList(orig)); List actList = Arrays.asList(act); System.out.println(origSet.removeAll(actList)); System.out.println(origSet);//from w ww .j a v a 2 s . c om }
From source file:MainClass.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set set = new HashSet(Arrays.asList(elements)); elements = new String[] { "B", "D", "F", "G", "1", "2", "3", "4" }; Set set2 = new HashSet(Arrays.asList(elements)); set.removeAll(set2); System.out.println(set);//from www. j a v a 2s . c o m }
From source file:FindDups2.java
public static void main(String[] args) { Set<String> uniques = new HashSet<String>(); Set<String> dups = new HashSet<String>(); for (String a : args) if (!uniques.add(a)) dups.add(a);/*from w ww.j a va 2 s.co m*/ uniques.removeAll(dups); System.out.println("Unique words: " + uniques); System.out.println("Duplicate words: " + dups); }
From source file:Main.java
public static void main(String[] a) { String elements[] = { "A", "B", "C", "D", "E" }; Set<String> set = new HashSet<String>(Arrays.asList(elements)); elements = new String[] { "B", "D", "F", "G", "1", "2", "3", "4" }; Set<String> set2 = new HashSet<String>(Arrays.asList(elements)); set.removeAll(set2); System.out.println(set);//from w w w.j a va 2 s. co m }
From source file:FindDupsAndUnique.java
public static void main(String args[]) { Set uniques = new HashSet(); Set dups = new HashSet(); String[] values = new String[] { "java", "java2", "java2s", "javas", "java" }; for (int i = 0; i < values.length; i++) if (!uniques.add(values[i])) dups.add(values[i]);/*from w w w . jav a 2 s. c o m*/ uniques.removeAll(dups); // Destructive set-difference System.out.println("Unique words: " + uniques); System.out.println("Duplicate words: " + dups); }
From source file:fr.inria.atlanmod.emf.graphs.Connectedness.java
public static void main(String[] args) { Options options = createOptions();/* ww w. ja va2 s .c o m*/ CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String inputMetamodel = commandLine.getOptionValue(INPUT_METAMODEL); String inputModel = commandLine.getOptionValue(INPUT_MODEL); Boolean logUnreachable = commandLine.hasOption(LOG_UNREACHABLE); ResourceSet resourceSet = new ResourceSetImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); { LOG.log(Level.INFO, "Loading input metamodel"); URI uri = URI.createFileURI(inputMetamodel); Resource resource = resourceSet.getResource(uri, true); registerEPackages(resource); } URI uri = URI.createFileURI(inputModel); LOG.log(Level.INFO, "Loading input model"); Resource resource = resourceSet.getResource(uri, true); LOG.log(Level.INFO, "Getting input model contents"); Set<EObject> resourceContents = getResourceContents(resource); int totalCount = resourceContents.size(); LOG.log(Level.INFO, MessageFormat.format("Input model contains {0} elements", totalCount)); List<EClassifier> candidateEClassifiers = buildCandidateEClassifiers(); for (Iterator<EObject> it = resource.getAllContents(); it.hasNext();) { EObject eObject = it.next(); if (candidateEClassifiers.contains(eObject.eClass())) { Set<EObject> reachableEObjects = getReachableEObjects(eObject); int i = reachableEObjects.size(); LOG.log(Level.INFO, MessageFormat.format("Found {0} reachable objects from {1} (EClass {2})", i, EcoreUtil.getURI(eObject), eObject.eClass().getName())); if (logUnreachable) { Set<EObject> unreachableEObjects = new HashSet<>(resourceContents); unreachableEObjects.removeAll(reachableEObjects); LOG.log(Level.INFO, MessageFormat.format("{0} elements are unreachable from {1} (EClass {2})", unreachableEObjects.size(), EcoreUtil.getURI(eObject), eObject.eClass().getName())); for (EObject unreachableEObject : unreachableEObjects) { LOG.log(Level.INFO, MessageFormat.format("Unreachable EObject {0} is of type {1}", EcoreUtil.getURI(unreachableEObject), unreachableEObject.eClass())); } } } } } catch (ParseException e) { LOG.log(Level.SEVERE, e.getLocalizedMessage(), e); LOG.log(Level.INFO, "Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { LOG.log(Level.SEVERE, e.getLocalizedMessage(), e); MessageUtil.showError(e.toString()); } }
From source file:net.ontopia.topicmaps.cmdlineutils.rdbms.RDBMSIndexTool.java
public static void main(String[] argv) throws Exception { // Initialize logging CmdlineUtils.initializeLogging();/*from w w w . j a v a 2s . c o m*/ // Register logging options CmdlineOptions options = new CmdlineOptions("RDBMSIndexTool", argv); CmdlineUtils.registerLoggingOptions(options); // Parse command line options try { options.parse(); } catch (CmdlineOptions.OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Get command line arguments String[] args = options.getArguments(); if (args.length != 1) { usage(); System.exit(3); } // load database schema project ClassLoader cloader = RDBMSIndexTool.class.getClassLoader(); InputStream istream = cloader.getResourceAsStream("net/ontopia/topicmaps/impl/rdbms/config/schema.xml"); Project dbp = DatabaseProjectReader.loadProject(istream); // open database connection String propfile = args[0]; ConnectionFactoryIF cf = new DefaultConnectionFactory(PropertyUtils.loadProperties(new File(propfile)), true); Connection conn = cf.requestConnection(); try { DatabaseMetaData dbm = conn.getMetaData(); boolean downcase = dbm.storesLowerCaseIdentifiers(); Map extra_indexes = new TreeMap(); Map missing_indexes = new TreeMap(); Iterator tables = dbp.getTables().iterator(); while (tables.hasNext()) { Table table = (Table) tables.next(); String table_name = (downcase ? table.getName().toLowerCase() : table.getName()); //! System.out.println("T :" + table_name); // get primary keys from database Map pkeys = getPrimaryKeys(table_name, dbm); // get indexes from database Map indexes = getIndexes(table_name, dbm); Map dindexes = new HashMap(); if (table.getPrimaryKeys() != null) { String pkey = table_name + '(' + StringUtils.join(table.getPrimaryKeys(), ',') + ')'; if (!pkeys.containsKey(pkey)) System.out.println("PKM: " + pkey); } Iterator iter = table.getIndexes().iterator(); while (iter.hasNext()) { Index index = (Index) iter.next(); String i = table_name + '(' + StringUtils.join(index.getColumns(), ',') + ')'; String index_name = (downcase ? index.getName().toLowerCase() : index.getName()); dindexes.put(i, index_name); } Set extra = new HashSet(indexes.keySet()); extra.removeAll(dindexes.keySet()); extra.removeAll(pkeys.keySet()); if (!extra.isEmpty()) { Iterator i = extra.iterator(); while (i.hasNext()) { Object k = i.next(); extra_indexes.put(k, indexes.get(k)); } } Set missing = new HashSet(dindexes.keySet()); missing.addAll(pkeys.keySet()); missing.removeAll(indexes.keySet()); if (!missing.isEmpty()) { Iterator i = missing.iterator(); while (i.hasNext()) { Object k = i.next(); missing_indexes.put(k, dindexes.get(k)); } } } if (!extra_indexes.isEmpty()) System.out.println("/* --- Extra indexes ----------------------------------------- */"); Iterator eiter = extra_indexes.keySet().iterator(); while (eiter.hasNext()) { Object k = eiter.next(); System.out.println("drop index " + extra_indexes.get(k) + "; /* " + k + " */"); } if (!missing_indexes.isEmpty()) System.out.println("/* --- Missing indexes---------------------------------------- */"); Iterator miter = missing_indexes.keySet().iterator(); while (miter.hasNext()) { Object k = miter.next(); System.out.println("create index " + missing_indexes.get(k) + " on " + k + ";"); } } finally { conn.rollback(); conn.close(); } }
From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java
/** * @param args// w ww . ja v a 2s. co m */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length == 0) { System.err.println("Specify at least one index type"); exitWithHelp(options); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); Set<String> selectedIndexes = new HashSet<String>(args.length); if (args.length == 1 && "all".equalsIgnoreCase(args[0])) selectedIndexes = AVAILIndexes; else selectedIndexes.addAll(Arrays.asList(args)); if (!AVAILIndexes.containsAll(selectedIndexes)) { selectedIndexes.removeAll(AVAILIndexes); StringBuilder err = new StringBuilder("Unknown Index types: "); for (String it : selectedIndexes) err.append(it).append(" "); System.err.println(err); exitWithHelp(options); } SDFTopologicalIndexer sdfIndexer = new SDFTopologicalIndexer(outFile, selectedIndexes); sdfIndexer.run(inFile); sdfIndexer.close(); }
From source file:Main.java
/** * Remove all entries from collection a that are in collection b and returns a new collection. *//*from ww w . j ava 2s .co m*/ public static <T> Set<T> removeAll(Collection<T> a, Collection<T> b) { Set<T> c = new HashSet<T>(a); c.removeAll(b); return c; }