List of usage examples for java.util LinkedHashSet LinkedHashSet
public LinkedHashSet()
From source file:Main.java
public static void main(String[] argv) throws Exception { Set<String> set = new LinkedHashSet<String>(); // Add some elements set.add("1"); set.add("2"); set.add("3"); set.add("2"); // List the elements for (Iterator it = set.iterator(); it.hasNext();) { Object o = it.next();// w ww . j a v a2s . co m } }
From source file:Main.java
public static void main(String[] args) { test(new LinkedHashSet()); }
From source file:Set2.java
public static void main(String[] args) { test(new HashSet()); test(new TreeSet()); test(new LinkedHashSet()); }
From source file:com.bright.utils.rmDuplicateLines.java
public static void main(String args) { File monfile = new File(args); Set<String> userIdSet = new LinkedHashSet<String>(); if (monfile.isFile() && monfile.getName().endsWith(".txt")) { try {/*from w w w . jav a 2 s . c om*/ List<String> content = FileUtils.readLines(monfile, Charset.forName("UTF-8")); userIdSet.addAll(content); Iterator<String> itr = userIdSet.iterator(); StringBuffer output = new StringBuffer(); while (itr.hasNext()) { output.append(itr.next() + System.getProperty("line.separator")); } BufferedWriter out = new BufferedWriter(new FileWriter(monfile)); String outText = output.toString(); out.write(outText); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:CollectionAll.java
public static void main(String[] args) { List list1 = new LinkedList(); list1.add("list"); list1.add("dup"); list1.add("x"); list1.add("dup"); traverse(list1);//from w w w. j av a2 s .c om List list2 = new ArrayList(); list2.add("list"); list2.add("dup"); list2.add("x"); list2.add("dup"); traverse(list2); Set set1 = new HashSet(); set1.add("set"); set1.add("dup"); set1.add("x"); set1.add("dup"); traverse(set1); SortedSet set2 = new TreeSet(); set2.add("set"); set2.add("dup"); set2.add("x"); set2.add("dup"); traverse(set2); LinkedHashSet set3 = new LinkedHashSet(); set3.add("set"); set3.add("dup"); set3.add("x"); set3.add("dup"); traverse(set3); Map m1 = new HashMap(); m1.put("map", "Java2s"); m1.put("dup", "Kava2s"); m1.put("x", "Mava2s"); m1.put("dup", "Lava2s"); traverse(m1.keySet()); traverse(m1.values()); SortedMap m2 = new TreeMap(); m2.put("map", "Java2s"); m2.put("dup", "Kava2s"); m2.put("x", "Mava2s"); m2.put("dup", "Lava2s"); traverse(m2.keySet()); traverse(m2.values()); LinkedHashMap /* from String to String */ m3 = new LinkedHashMap(); m3.put("map", "Java2s"); m3.put("dup", "Kava2s"); m3.put("x", "Mava2s"); m3.put("dup", "Lava2s"); traverse(m3.keySet()); traverse(m3.values()); }
From source file:ZipCompare.java
public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: zipcompare [file1] [file2]"); System.exit(1);// w w w .j a va 2s . c o m } ZipFile file1; try { file1 = new ZipFile(args[0]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } ZipFile file2; try { file2 = new ZipFile(args[1]); } catch (IOException e) { System.out.println("Could not open zip file " + args[0] + ": " + e); System.exit(1); return; } System.out.println("Comparing " + args[0] + " with " + args[1] + ":"); Set set1 = new LinkedHashSet(); for (Enumeration e = file1.entries(); e.hasMoreElements();) set1.add(((ZipEntry) e.nextElement()).getName()); Set set2 = new LinkedHashSet(); for (Enumeration e = file2.entries(); e.hasMoreElements();) set2.add(((ZipEntry) e.nextElement()).getName()); int errcount = 0; int filecount = 0; for (Iterator i = set1.iterator(); i.hasNext();) { String name = (String) i.next(); if (!set2.contains(name)) { System.out.println(name + " not found in " + args[1]); errcount += 1; continue; } try { set2.remove(name); if (!streamsEqual(file1.getInputStream(file1.getEntry(name)), file2.getInputStream(file2.getEntry(name)))) { System.out.println(name + " does not match"); errcount += 1; continue; } } catch (Exception e) { System.out.println(name + ": IO Error " + e); e.printStackTrace(); errcount += 1; continue; } filecount += 1; } for (Iterator i = set2.iterator(); i.hasNext();) { String name = (String) i.next(); System.out.println(name + " not found in " + args[0]); errcount += 1; } System.out.println(filecount + " entries matched"); if (errcount > 0) { System.out.println(errcount + " entries did not match"); System.exit(1); } System.exit(0); }
From source file:org.test.LookupSVNUsers.java
/** * @param args//from ww w .j av a2 s . c o m * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 2) { log.error("USAGE: <svn users file(input)> <git authors file (output)>"); System.exit(-1); } Set<String> unmatchedNameSet = new LinkedHashSet<String>(); Map<String, GitUser> gitUserMap = new LinkedHashMap<String, GitUser>(); String svnAuthorsFile = args[0]; List<String> lines = FileUtils.readLines(new File(svnAuthorsFile)); for (String line : lines) { // intentionally handle both upper and lower case varients of the same name. String svnUserName = line.trim(); if (svnUserName.contains("(")) continue; // skip over this line as we can't use it on the url if (gitUserMap.keySet().contains(svnUserName)) continue; // skip this duplicate. log.info("starting on user = " + svnUserName); String gitName = extractFullName(svnUserName); if (gitName == null) { gitName = extractFullName(svnUserName.toLowerCase()); } if (gitName == null) { unmatchedNameSet.add(svnUserName); } else { gitUserMap.put(svnUserName, new GitUser(svnUserName, gitName)); log.info("mapped user (" + svnUserName + ") to: " + gitName); } } List<String> mergedList = new ArrayList<String>(); mergedList.add("# GENERATED "); List<String> userNameList = new ArrayList<String>(); userNameList.addAll(gitUserMap.keySet()); Collections.sort(userNameList); for (String userName : userNameList) { GitUser gUser = gitUserMap.get(userName); mergedList.add(gUser.getSvnAuthor() + " = " + gUser.getGitUser() + " <" + gUser.getSvnAuthor() + "@users.sourceforge.net>"); } for (String username : unmatchedNameSet) { log.warn("failed to match SVN User = " + username); // add in the unmatched entries as is. mergedList.add(username + " = " + username + " <" + username + "@users.sourceforge.net>"); } FileUtils.writeLines(new File(args[1]), "UTF-8", mergedList); }
From source file:de.jetwick.snacktory.HtmlFetcher.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new FileReader("urls.txt")); String line = null;/*from w w w . ja v a2 s. c o m*/ Set<String> existing = new LinkedHashSet<String>(); while ((line = reader.readLine()) != null) { int index1 = line.indexOf("\""); int index2 = line.indexOf("\"", index1 + 1); String url = line.substring(index1 + 1, index2); String domainStr = SHelper.extractDomain(url, true); String counterStr = ""; // TODO more similarities if (existing.contains(domainStr)) counterStr = "2"; else existing.add(domainStr); String html = new HtmlFetcher().fetchAsString(url, 20000); String outFile = domainStr + counterStr + ".html"; BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); writer.write(html); writer.close(); } reader.close(); }
From source file:edu.ucsb.cs.eager.sa.cerebro.ProfessorX.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", "input-file", true, "Path to input xml file"); options.addOption("r", "root-path", true, "Root path of all Git repositories"); CommandLine cmd;/*from ww w .ja v a2 s . c o m*/ try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Cerebro", options); return; } String inputFileName = cmd.getOptionValue("i"); if (inputFileName == null) { System.err.println("input file path is required"); return; } String rootPath = cmd.getOptionValue("r"); if (rootPath == null) { System.err.println("root path is required"); return; } File inputFile = new File(inputFileName); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); Document doc; try { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); doc = dBuilder.parse(inputFile); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); return; } NodeList repoList = doc.getElementsByTagName("repo"); for (int i = 0; i < repoList.getLength(); i++) { Element repo = (Element) repoList.item(i); String name = repo.getElementsByTagName("name").item(0).getTextContent(); String classPath = repo.getElementsByTagName("classpath").item(0).getTextContent(); Set<String> classes = new LinkedHashSet<String>(); NodeList classesList = repo.getElementsByTagName("classes").item(0).getChildNodes(); for (int j = 0; j < classesList.getLength(); j++) { if (!(classesList.item(j) instanceof Element)) { continue; } classes.add(classesList.item(j).getTextContent()); } analyzeRepo(rootPath, name, classPath, classes); } }
From source file:com.joliciel.jochre.search.JochreSearch.java
/** * @param args//ww w.ja va 2s . c o m */ public static void main(String[] args) { try { Map<String, String> argMap = new HashMap<String, String>(); for (String arg : args) { int equalsPos = arg.indexOf('='); String argName = arg.substring(0, equalsPos); String argValue = arg.substring(equalsPos + 1); argMap.put(argName, argValue); } String command = argMap.get("command"); argMap.remove("command"); String logConfigPath = argMap.get("logConfigFile"); if (logConfigPath != null) { argMap.remove("logConfigFile"); Properties props = new Properties(); props.load(new FileInputStream(logConfigPath)); PropertyConfigurator.configure(props); } LOG.debug("##### Arguments:"); for (Entry<String, String> arg : argMap.entrySet()) { LOG.debug(arg.getKey() + ": " + arg.getValue()); } SearchServiceLocator locator = SearchServiceLocator.getInstance(); SearchService searchService = locator.getSearchService(); if (command.equals("buildIndex")) { String indexDirPath = argMap.get("indexDir"); String documentDirPath = argMap.get("documentDir"); File indexDir = new File(indexDirPath); indexDir.mkdirs(); File documentDir = new File(documentDirPath); JochreIndexBuilder builder = searchService.getJochreIndexBuilder(indexDir); builder.updateDocument(documentDir); } else if (command.equals("updateIndex")) { String indexDirPath = argMap.get("indexDir"); String documentDirPath = argMap.get("documentDir"); boolean forceUpdate = false; if (argMap.containsKey("forceUpdate")) { forceUpdate = argMap.get("forceUpdate").equals("true"); } File indexDir = new File(indexDirPath); indexDir.mkdirs(); File documentDir = new File(documentDirPath); JochreIndexBuilder builder = searchService.getJochreIndexBuilder(indexDir); builder.updateIndex(documentDir, forceUpdate); } else if (command.equals("search")) { HighlightServiceLocator highlightServiceLocator = HighlightServiceLocator.getInstance(locator); HighlightService highlightService = highlightServiceLocator.getHighlightService(); String indexDirPath = argMap.get("indexDir"); File indexDir = new File(indexDirPath); JochreQuery query = searchService.getJochreQuery(argMap); JochreIndexSearcher searcher = searchService.getJochreIndexSearcher(indexDir); TopDocs topDocs = searcher.search(query); Set<Integer> docIds = new LinkedHashSet<Integer>(); for (ScoreDoc scoreDoc : topDocs.scoreDocs) { docIds.add(scoreDoc.doc); } Set<String> fields = new HashSet<String>(); fields.add("text"); Highlighter highlighter = highlightService.getHighlighter(query, searcher.getIndexSearcher()); HighlightManager highlightManager = highlightService .getHighlightManager(searcher.getIndexSearcher()); highlightManager.setDecimalPlaces(query.getDecimalPlaces()); highlightManager.setMinWeight(0.0); highlightManager.setIncludeText(true); highlightManager.setIncludeGraphics(true); Writer out = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); if (command.equals("highlight")) { highlightManager.highlight(highlighter, docIds, fields, out); } else { highlightManager.findSnippets(highlighter, docIds, fields, out); } } else { throw new RuntimeException("Unknown command: " + command); } } catch (RuntimeException e) { LogUtils.logError(LOG, e); throw e; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }