List of usage examples for java.util LinkedHashSet add
boolean add(E e);
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);// w w w .j a v 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:nl.systemsgenetics.functionenrichmentoftransqtls.CorrelateSumChi2ToPathways.java
/** * @param args the command line arguments *//* ww w. j a va 2 s . c o m*/ public static void main(String[] args) throws IOException { final File pathwayMatrixFile = new File(args[0]); final File significantTermsFile = new File(args[1]); final File sumChi2MatrixFile = new File(args[2]); final File transQtlEnrichmentsMatrixFile = new File(args[3]); System.out.println("Pathway file: " + pathwayMatrixFile.getPath()); System.out.println("Pathway significant terms file: " + significantTermsFile.getPath()); System.out.println("SumChi2 file: " + sumChi2MatrixFile.getPath()); System.out.println("Output file: " + transQtlEnrichmentsMatrixFile.getPath()); LinkedHashSet<String> significantTerms = loadSignificantTerms(significantTermsFile); DoubleMatrixDataset<String, String> pathwayMatrix = DoubleMatrixDataset .loadDoubleData(pathwayMatrixFile.getPath()); DoubleMatrixDataset<String, String> sumChi2Matrix = DoubleMatrixDataset .loadDoubleData(sumChi2MatrixFile.getPath()); LinkedHashSet<String> genesInBoth = new LinkedHashSet<String>(); for (String gene : pathwayMatrix.getHashRows().keySet()) { if (sumChi2Matrix.containsRow(gene)) { genesInBoth.add(gene); } } pathwayMatrix = pathwayMatrix.viewColSelection(significantTerms); pathwayMatrix = pathwayMatrix.viewRowSelection(genesInBoth); DoubleMatrixDataset<String, String> transQtlEnrichmentsMatrix = new DoubleMatrixDataset<String, String>( pathwayMatrix.getHashCols(), sumChi2Matrix.getHashCols()); sumChi2Matrix = sumChi2Matrix.viewRowSelection(genesInBoth); System.out.println("Genes in both datasets: " + genesInBoth.size()); System.out.println("Pathways to test: " + pathwayMatrix.columns()); final SimpleRegression regression = new SimpleRegression(); final DoubleRandomEngine randomEngine = new DRand(); StudentT tDistColt = new StudentT(sumChi2Matrix.rows() / 2 - 2, randomEngine); for (String trait : sumChi2Matrix.getColObjects()) { System.out.println("Trait: " + trait); DoubleMatrix1D traitSumChi2 = sumChi2Matrix.getCol(trait); for (String pathway : pathwayMatrix.getColObjects()) { DoubleMatrix1D pathwayScores = pathwayMatrix.getCol(pathway); regression.clear(); for (int i = 0; i < traitSumChi2.size(); ++i) { //System.out.println(traitSumChi2.get(i) + " & " + pathwayScores.get(i)); regression.addData(traitSumChi2.get(i), pathwayScores.get(i)); } double r = regression.getR(); //System.out.println(trait + " " + pathway + " " + r); double t = r / (Math.sqrt((1 - r * r) / (double) (traitSumChi2.size() / 2 - 2))); double pValue; double zScore; if (t < 0) { pValue = tDistColt.cdf(t); if (pValue < 2.0E-323) { pValue = 2.0E-323; } zScore = Probability.normalInverse(pValue); } else { pValue = tDistColt.cdf(-t); if (pValue < 2.0E-323) { pValue = 2.0E-323; } zScore = -Probability.normalInverse(pValue); } pValue *= 2; transQtlEnrichmentsMatrix.setElement(pathway, trait, zScore); } } transQtlEnrichmentsMatrix.save(transQtlEnrichmentsMatrixFile); }
From source file:unige.cui.meghdad.nlp.mwe2.MAIN_File.java
public static void main(String[] args) throws ParseException, FileNotFoundException, IOException { //====================================================================== //====================== COMMAND LINE ARGUMENTS ======================= //====================================================================== //use apache commons CLI to parse command line arguments // create Options object Options options = new Options(); //required options: options.addOption("p2candidates", true, "Path 2 Not POS Tagged Candidates."); options.addOption("p2corpus", true, "Path 2 POS tagged corpus."); options.addOption("p2wr", true, "Path 2 word representations."); options.addOption("size", true, "Size/length of word representations."); //optional options: options.addOption("rc", true, "Model: m1 or m2."); options.addOption("maxRank", true, "Return MWEs up to this rank."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); //initialize options to default values and check if the required options are set if (!cmd.hasOption("p2corpus")) { System.out.println("Path to the POS tagged corpus must be set."); }//from w w w .j a va 2 s.c om if (!cmd.hasOption("p2wr")) { System.out.println("A valid word representation must be specified."); return; } if (!cmd.hasOption("p2candidates")) { System.out.println("A valid candidate list must be specified."); return; } int maxRank = 200; if (cmd.hasOption("maxRank")) { maxRank = Integer.parseInt(cmd.getOptionValue("maxRank")); } String model = "m2"; if (cmd.hasOption("rc")) { model = cmd.getOptionValue("rc"); } int rl = -1; if (cmd.hasOption("size")) { rl = Integer.parseInt(cmd.getOptionValue("size")); } else { System.out.println("Size/length of word representations must be specified."); return; } //====================================================================== //====================================================================== String p2corpus = cmd.getOptionValue("p2corpus"); String p2candidates = cmd.getOptionValue("p2candidates"); String p2wr = cmd.getOptionValue("p2wr"); Tools T = new Tools(); //=================== related to KNN =================== //create an instance of class ReadAndFilterWordRep System.out.println("Reading word representations..."); ReadAndFilterWordRep rv = new ReadAndFilterWordRep(); //word2vec output entries are unique, so the following lists are going //to be lists of unique vectors (with no duplicate) List<List<String>> wordsVectors = rv.rfwr(p2wr, rl); HashMap<String, Integer> words = new HashMap<>(); //for words, use HashMap insteaf of list for faster look up (contains) //preserve the index of the words as Map values for future use for (int i = 0; i < wordsVectors.get(0).size(); i++) { words.put(wordsVectors.get(0).get(i), i); } //for vectors, use a List List<String> vectors = wordsVectors.get(1); //================ end of related to KNN ================== System.out.println("Extracting 1-grams..."); //ExtractUnigram(String p2corpus, int lexFreqThreshold, boolean isPosTagged, boolean ignoreCase) HashMap<String, Integer> unigrams = T.ExtractUnigram(p2corpus, 1, false, true).get(0); System.out.println("Extracting 2-grams..."); //ExtractNgrams(String p2corpus, int freqThreshold, int order, boolean isCorpusPosTagged, boolean outputPosTagged, boolean ignoreCase) HashMap<String, Integer> bigrams = T.ExtractNgrams(p2corpus, 1, 2, false, false, true); System.out.println("Reading candidates..."); BufferedReader candidateFile = new BufferedReader( new InputStreamReader(new FileInputStream(p2candidates), "UTF8")); //TODO add exceptions when candidate list could not be created or is empty //TODO add , to the pattern. so that candidates be split around comma or space not just space //TODO make sure k is always > SYNSETSIZE (arg of nonSubFeatExtractConstituentDetails) /* Since at this point no frequency information is needed, I put the candidates in a HashSet instead of a HashMap. */ LinkedHashSet<String> candidates = new LinkedHashSet<>(); String Entry = ""; Pattern entryETfreq = Pattern.compile("(\\w+\\s\\w+)\\s?(\\d+)?$"); Matcher entryETfreqM; while ((Entry = candidateFile.readLine()) != null) { entryETfreqM = entryETfreq.matcher(Entry); if (entryETfreqM.find()) { candidates.add(entryETfreqM.group(1)); } } /* The map of compounds must be broken into a list of words (I) because knnExhSearch works with a list of words and not compounds. Then in II, this the compounds will be reconstructed, this time together with their neighbors. */ String[] wis; List<String> avail_lw_Rep = new ArrayList<>(); List<String> avail_lw_forms = new ArrayList<>(); //(I) for (String c : candidates) { wis = c.split(" "); for (String w : wis) { if (words.containsKey(w)) { int index_of_l = words.get(w); if (!avail_lw_forms.contains(w)) { avail_lw_Rep.add(vectors.get(index_of_l)); avail_lw_forms.add(w); } } else { System.out.println( "Vector representation for\" " + c + "\" is not availble. Skipping this entry."); } } } //Find nearest neighbors: //create an instance of Transform class Transform Tr = new Transform(); //transform the representations (avail_lw_Rep) of avail_lw_forms from string to double System.out.println("Transforming word representations from String to Double"); List<List<Double>> M = Tr.createFromList(vectors, rl); List<List<Double>> lw = Tr.createFromList(avail_lw_Rep, rl); //create an instance of KNN class KNN knn = new KNN(); /* lwNeighbors contains a list of indices pointing to the neighbors for each word in avail_lw_forms. lwNeighbors and avail_lw_forms have the same size. Each index of lwNeighbors corresponds to the same index in avail_lw_forms. */ System.out.println("Executing knn exhustive search for the components of the candidates..."); List<List<Integer>> lwNeighbors = knn.knnExhSearch(lw, M, 7); //(II) /* - Read the candidates again. - Split each candidate into its components. - Check if both those two components are found in avail_lw_forms, i.e., for both of the components a vector representation was found, then write it to results. */ //compounds and the neighbors for each component of the compound. List<String> compoundAndComponNeighbors = new ArrayList<>(); /* entry contains the compound and the neighbors of each of its components. format: vehicle,wrap,vehicle,vehicles,truck,car,airbag,gear,semi-trailer,wrap,wrapping,wrapped,wraps,glued,stitched,sewn */ System.out.println("Constructing candidate list with neighbors..."); String entry = ""; for (String c : candidates) { wis = c.split(" "); /* If both of the components of the compound had representation (and hence a neighbors were found for them) update entry and add it to the results: compoundAndComponNeighbors */ if (avail_lw_forms.contains(wis[0]) && avail_lw_forms.contains(wis[1])) { entry = wis[0].concat(",").concat(wis[1]).concat(","); List<Integer> w1Neighbors = lwNeighbors.get(avail_lw_forms.indexOf(wis[0])); for (int neighbInd : w1Neighbors) { entry = entry.concat(wordsVectors.get(0).get(neighbInd)).concat(","); } List<Integer> w2Neighbors = lwNeighbors.get(avail_lw_forms.indexOf(wis[1])); //counter to identify the last neighbor (to avoid adding a trailing comma) int co = 0; for (int neighbInd : w2Neighbors) { entry = entry.concat(wordsVectors.get(0).get(neighbInd)); if (co < w2Neighbors.size() - 1) { entry = entry.concat(","); co++; } } compoundAndComponNeighbors.add(entry); entry = ""; } else { /* The neighbors could not be retrieved for at least one of the components of this compound and therefore it will not be added to the return list. */ } } /* Run SDMA.nonSubFeatExtractConstituentDetails to calculate SDMAs for each one of the candidates. */ System.out.println("Calculating SDMAs..."); SDMA sdma = new SDMA(); HashMap<String, Double> sdmaScores = sdma.nonSubFeatExtractConstituentDetails(compoundAndComponNeighbors, bigrams, unigrams, 5, 7, model, true, true); //sort (descending) candidates by their score: List<Map.Entry<String, Double>> entryList = new ArrayList<Map.Entry<String, Double>>(sdmaScores.entrySet()); Collections.sort(entryList, new Comparator<Map.Entry<String, Double>>() { @Override public int compare(Map.Entry<String, Double> e1, Map.Entry<String, Double> e2) { return -1 * e1.getValue().compareTo(e2.getValue()); } }); //print the results: DecimalFormat df = new DecimalFormat("0.000"); System.out.println("Ranking the candidates...\n"); for (Map.Entry<String, Double> e : entryList) { System.out.println(e.getKey() + " " + df.format(e.getValue())); } }
From source file:org.jf.smali.main.java
/** * Run!//from w w w.j a v a 2 s . c o m */ public static void main(String[] args) { Locale locale = new Locale("en", "US"); Locale.setDefault(locale); CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } int jobs = -1; boolean allowOdex = false; boolean verboseErrors = false; boolean printTokens = false; int apiLevel = 15; String outputDexFile = "out.dex"; String[] remainingArgs = commandLine.getArgs(); Option[] options = commandLine.getOptions(); for (int i = 0; i < options.length; i++) { Option option = options[i]; String opt = option.getOpt(); switch (opt.charAt(0)) { case 'v': version(); return; case '?': while (++i < options.length) { if (options[i].getOpt().charAt(0) == '?') { usage(true); return; } } usage(false); return; case 'o': outputDexFile = commandLine.getOptionValue("o"); break; case 'x': allowOdex = true; break; case 'a': apiLevel = Integer.parseInt(commandLine.getOptionValue("a")); break; case 'j': jobs = Integer.parseInt(commandLine.getOptionValue("j")); break; case 'V': verboseErrors = true; break; case 'T': printTokens = true; break; default: assert false; } } if (remainingArgs.length == 0) { usage(); return; } try { LinkedHashSet<File> filesToProcess = new LinkedHashSet<File>(); for (String arg : remainingArgs) { File argFile = new File(arg); if (!argFile.exists()) { throw new RuntimeException("Cannot find file or directory \"" + arg + "\""); } if (argFile.isDirectory()) { getSmaliFilesInDir(argFile, filesToProcess); } else if (argFile.isFile()) { filesToProcess.add(argFile); } } if (jobs <= 0) { jobs = Runtime.getRuntime().availableProcessors(); if (jobs > 6) { jobs = 6; } } boolean errors = false; final DexBuilder dexBuilder = DexBuilder.makeDexBuilder(apiLevel); ExecutorService executor = Executors.newFixedThreadPool(jobs); List<Future<Boolean>> tasks = Lists.newArrayList(); final boolean finalVerboseErrors = verboseErrors; final boolean finalPrintTokens = printTokens; final boolean finalAllowOdex = allowOdex; final int finalApiLevel = apiLevel; for (final File file : filesToProcess) { tasks.add(executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return assembleSmaliFile(file, dexBuilder, finalVerboseErrors, finalPrintTokens, finalAllowOdex, finalApiLevel); } })); } for (Future<Boolean> task : tasks) { while (true) { try { if (!task.get()) { errors = true; } } catch (InterruptedException ex) { continue; } break; } } executor.shutdown(); if (errors) { System.exit(1); } dexBuilder.writeTo(new FileDataStore(new File(outputDexFile))); } catch (RuntimeException ex) { System.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:"); ex.printStackTrace(); System.exit(2); } catch (Throwable ex) { System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:"); ex.printStackTrace(); System.exit(3); } }
From source file:org.cc.smali.main.java
/** * Run!/*from w ww . j av a2 s. c o m*/ */ public static void main(String[] args) { Locale locale = new Locale("en", "US"); Locale.setDefault(locale); CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } int jobs = -1; boolean allowOdex = false; boolean verboseErrors = false; boolean printTokens = false; boolean experimental = false; int apiLevel = 15; String outputDexFile = "out.dex"; String[] remainingArgs = commandLine.getArgs(); Option[] options = commandLine.getOptions(); for (int i = 0; i < options.length; i++) { Option option = options[i]; String opt = option.getOpt(); switch (opt.charAt(0)) { case 'v': version(); return; case '?': while (++i < options.length) { if (options[i].getOpt().charAt(0) == '?') { usage(true); return; } } usage(false); return; case 'o': outputDexFile = commandLine.getOptionValue("o"); break; case 'x': allowOdex = true; break; case 'X': experimental = true; break; case 'a': apiLevel = Integer.parseInt(commandLine.getOptionValue("a")); break; case 'j': jobs = Integer.parseInt(commandLine.getOptionValue("j")); break; case 'V': verboseErrors = true; break; case 'T': printTokens = true; break; default: assert false; } } if (remainingArgs.length == 0) { usage(); return; } try { LinkedHashSet<File> filesToProcess = new LinkedHashSet<File>(); for (String arg : remainingArgs) { File argFile = new File(arg); if (!argFile.exists()) { throw new RuntimeException("Cannot find file or directory \"" + arg + "\""); } if (argFile.isDirectory()) { getSmaliFilesInDir(argFile, filesToProcess); } else if (argFile.isFile()) { filesToProcess.add(argFile); } } if (jobs <= 0) { jobs = Runtime.getRuntime().availableProcessors(); if (jobs > 6) { jobs = 6; } } boolean errors = false; final DexBuilder dexBuilder = DexBuilder.makeDexBuilder(apiLevel); ExecutorService executor = Executors.newFixedThreadPool(jobs); List<Future<Boolean>> tasks = Lists.newArrayList(); final boolean finalVerboseErrors = verboseErrors; final boolean finalPrintTokens = printTokens; final boolean finalAllowOdex = allowOdex; final int finalApiLevel = apiLevel; final boolean finalExperimental = experimental; for (final File file : filesToProcess) { tasks.add(executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return assembleSmaliFile(file, dexBuilder, finalVerboseErrors, finalPrintTokens, finalAllowOdex, finalApiLevel, finalExperimental); } })); } for (Future<Boolean> task : tasks) { while (true) { try { if (!task.get()) { errors = true; } } catch (InterruptedException ex) { continue; } break; } } executor.shutdown(); if (errors) { System.exit(1); } dexBuilder.writeTo(new FileDataStore(new File(outputDexFile))); } catch (RuntimeException ex) { System.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:"); ex.printStackTrace(); System.exit(2); } catch (Throwable ex) { System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:"); ex.printStackTrace(); System.exit(3); } }
From source file:Main.java
public static LinkedHashSet<String> convertStringToSet(String input) { String[] array = input.split(","); LinkedHashSet<String> list = new LinkedHashSet<>(); for (int i = 0; i < array.length; i++) { list.add(array[i]); }//from w w w . ja v a 2s .co m return list; }
From source file:Main.java
public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) { if ((args == null) || (args.length == 0)) { return new LinkedHashSet(); }//from www .j a v a 2 s. c om LinkedHashSet<T> set = new LinkedHashSet(args.length); for (V v : args) { set.add(v); } return set; }
From source file:Main.java
/** * Returns the array as a set//from w w w . ja va 2 s .co m */ public static <T> LinkedHashSet<T> asLinkedHashSet(T[] array) { LinkedHashSet<T> set = new LinkedHashSet<T>(); for (T obj : array) { set.add(obj); } return set; }
From source file:Main.java
public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) { if (args == null || args.length == 0) { return new LinkedHashSet<T>(); }// w w w. j a v a 2 s. c o m LinkedHashSet<T> set = new LinkedHashSet<T>(args.length); for (V v : args) { set.add(v); } return set; }
From source file:Main.java
public static <T> LinkedHashSet<T> asLinkedHashSetRemoveNulls(T[] elements) { LinkedHashSet<T> result = new LinkedHashSet<>(elements.length); for (T element : elements) { if (element != null) { result.add(element); }/*from w w w. jav a 2s. co m*/ } return result; }