List of usage examples for java.util HashMap containsKey
public boolean containsKey(Object key)
From source file:com.prasanna.android.stacknetwork.service.QuestionServiceHelper.java
private void getCommensAndUpdateAnswer(String answerIds, HashMap<Long, Answer> idAnswerMap) { boolean hasMore = true; int page = 1; while (hasMore) { StackXPage<Comment> commentsPage = getComments(StringConstants.ANSWERS, answerIds, page++); if (commentsPage != null && commentsPage.items != null) { for (Comment comment : commentsPage.items) { if (idAnswerMap.containsKey(comment.post_id)) { if (idAnswerMap.get(comment.post_id).comments == null) idAnswerMap.get(comment.post_id).comments = new ArrayList<Comment>(); idAnswerMap.get(comment.post_id).comments.add(comment); }/* www .j av a 2 s . c om*/ } hasMore = commentsPage.hasMore; } else hasMore = false; } }
From source file:gov.nih.nci.cabig.caaers.web.study.DiseaseTab.java
@Override protected void validate(StudyCommand command, BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups, Errors errors) {// www . j a va 2 s.c o m HashMap<String, DiseaseTerm> ctepTermMap = new HashMap<String, DiseaseTerm>(); for (CtepStudyDisease ctepDisease : command.getStudy().getCtepStudyDiseases()) { if (ctepDisease.isRetired()) continue; ctepTermMap.put(ctepDisease.getTerm().getId().toString(), ctepDisease.getDiseaseTerm()); } String[] newCTEPTermIds = command.getDiseaseTermIds(); if (newCTEPTermIds != null) { for (String newCTEPTermId : newCTEPTermIds) { if (ctepTermMap.containsKey(newCTEPTermId)) { errors.reject("STU_005", new Object[] { ctepTermMap.get(newCTEPTermId).getFullName() }, "'" + ctepTermMap.get(newCTEPTermId).getFullName() + "' is already associated to this study"); } } } HashMap<String, LowLevelTerm> medraTermMap = new HashMap<String, LowLevelTerm>(); for (MeddraStudyDisease meddraStudyDisease : command.getStudy().getMeddraStudyDiseases()) { if (meddraStudyDisease.isRetired()) continue; medraTermMap.put(meddraStudyDisease.getTerm().getId().toString(), meddraStudyDisease.getTerm()); } if (command.getDiseaseLlt() != null) { if (medraTermMap.containsKey(command.getDiseaseLlt())) { errors.reject("STU_005", new Object[] { medraTermMap.get(command.getDiseaseLlt()).getFullName() }, "'" + medraTermMap.get(command.getDiseaseLlt()).getFullName() + "' is already associated to this study"); command.setDiseaseLlt(null); } } if (checkDuplicateConditionById(conditionMap, command.getCondition())) { errors.reject("DUPLICATE_STUDY_CONDITION", new Object[] { (conditionMap.get(command.getCondition())).getConditionName() }, ""); } }
From source file:Business.InvertedIndex.java
public List findReleventDocs(/*Matcher matcher*/String[] queryTerms) { DocInfo queryDoc = new DocInfo("queryTerm", null, null); populateInvertedIndex(/*matcher*/queryTerms, "qureyTerm", queryDoc); documents.put("queryTerm", queryDoc); // queryDoc.calculateLengthNormalisationCoffecient(documents.size()); queryDoc.lengthNormalize(documents.size()); Collection<DocTermInfo> queryTermsInfo = queryDoc.getTermsInADocument().values(); Iterator i = queryTermsInfo.iterator(); HashMap<DocInfo, Double> scores = new HashMap<>(); while (i.hasNext()) { DocTermInfo queryTerm = (DocTermInfo) i.next(); Collection docs = queryTerm.getTermInfo().getDocuments().values(); Iterator docIt = docs.iterator(); while (docIt.hasNext()) { DocInfo doc = (DocInfo) docIt.next(); if (doc.getDocId() != "queryTerm") { // doc.calculateLengthNormalisationCoffecient(documents.size()); doc.lengthNormalize(documents.size()); if (scores.containsKey(doc)) { double score = scores.get(doc) + (doc.getTermsInADocument().get(queryTerm.getTerm()).getFinalCoffecient()) * (queryTerm.getFinalCoffecient()); scores.put(doc, score); } else { double score = (doc.getTermsInADocument().get(queryTerm.getTerm()).getFinalCoffecient()) * (queryTerm.getFinalCoffecient()); scores.put(doc, score); }//w w w . j a v a2 s . co m } } } Set<DocInfo> set = scores.keySet(); List<DocInfo> sortedDocs = new ArrayList<>(set); Collections.sort(sortedDocs, new Comparator<DocInfo>() { @Override public int compare(DocInfo s1, DocInfo s2) { return Double.compare(scores.get(s2), scores.get(s1)); } }); return sortedDocs; }
From source file:it.geosolutions.operations.FileBrowserOperationController.java
/** * Provide a HashMap of every LocalOperation bean loaded * @return/* w ww . j av a 2s. c om*/ */ private HashMap<String, List<Operation>> getAvailableOperations() { HashMap<String, List<Operation>> ocontrollersHashMap = new HashMap<String, List<Operation>>(); String[] lista = applicationContext.getBeanNamesForType(LocalOperation.class); for (String s : lista) { LocalOperation fo = (LocalOperation) applicationContext.getBean(s); if (!fo.isMultiple()) { List<String> exts = fo.getExtensions(); for (String extString : exts) { if (ocontrollersHashMap.containsKey(extString)) { ocontrollersHashMap.get(extString).add(fo); } else { List<Operation> olist = new ArrayList<Operation>(); olist.add(fo); ocontrollersHashMap.put(extString, olist); } } } } return ocontrollersHashMap; }
From source file:com.sfs.beans.GadgetBean.java
/** * Get the value.//from w w w. j ava2 s .co m * * @param keyVal the key * @param gadgetPreferences the gadget preferences * * @return the string */ private String getValue(final String keyVal, final GadgetPreferencesBean gadgetPreferences) { String value = ""; if (gadgetPreferences.getUserPref(keyVal) != null) { value = gadgetPreferences.getUserPref(keyVal); } HashMap<String, HashMap<String, Object>> userPrefs = this.getUserPreferences(); if (userPrefs != null) { if (userPrefs.containsKey(keyVal)) { HashMap<String, Object> userPref = userPrefs.get(keyVal); String dataType = (String) userPref.get("datatype"); if (dataType != null) { if (dataType.compareToIgnoreCase("bool") == 0) { if (value.compareToIgnoreCase("true") == 0) { value = "1"; } else { value = "0"; } } } } } return value; }
From source file:com.bbc.remarc.util.ResourceManager.java
private static void processUploadDir(File uploadFolder, String resourcesDir) { log.debug("processing resources within " + uploadFolder.getPath()); List<File> directories = new ArrayList<File>(); HashMap<String, List<File>> fileMap = new HashMap<String, List<File>>(); HashMap<String, ResourceType> typeMap = new HashMap<String, ResourceType>(); File properties = null;/* w w w . j ava 2s. c om*/ //iterate through all files in the upload folder File[] contents = uploadFolder.listFiles(); for (File f : contents) { String filename = f.getName(); //if the file is a directory, add it to the list, we'll process this later. if (f.isDirectory()) { log.debug("directory: " + filename); directories.add(f); } else { String extension = FilenameUtils.getExtension(filename); String nameId = FilenameUtils.getBaseName(filename); log.debug("file: " + nameId + "(" + extension + ")"); //determine the type of resource for the FILE ResourceType resourceType = getTypeFromExtension(extension); if (resourceType == null) { log.debug("unrecognised extention (" + extension + "), skipping file"); } else if (resourceType == ResourceType.PROPERTIES) { log.debug("found the properties file"); properties = f; } else { //add the file to the fileMap, key'd on the nameId if (!fileMap.containsKey(nameId)) { List<File> fileList = new ArrayList<File>(); fileList.add(f); fileMap.put(nameId, new ArrayList<File>(fileList)); } else { fileMap.get(nameId).add(f); } //get the current type of resource for the DOCUMENT & update it: VIDEO > AUDIO > IMAGES ResourceType documentType = (typeMap.containsKey(nameId)) ? typeMap.get(nameId) : ResourceType.IMAGE; documentType = (resourceType.getValue() > documentType.getValue()) ? resourceType : documentType; //add the document type to the typeMap, key'd on the nameId typeMap.put(nameId, documentType); } } } createDocumentsFromFileMap(fileMap, typeMap, properties, resourcesDir); log.debug("upload finished for " + uploadFolder.getPath()); //now call the same method for each directory for (File dir : directories) { processUploadDir(dir, resourcesDir); } }
From source file:it.crs4.seal.read_sort.MergeAlignments.java
private Map<String, String> parseReadGroupOptions(Map<String, Option> readGroupOptions, CommandLine args) throws ParseException { HashMap<String, String> fields = new HashMap<String, String>(); for (Map.Entry<String, Option> pair : readGroupOptions.entrySet()) { String fieldName = pair.getKey(); Option opt = pair.getValue(); if (args.hasOption(opt.getOpt())) { fields.put(fieldName, args.getOptionValue(opt.getOpt())); }/*from www.j a v a2 s. c o m*/ } if (!fields.isEmpty()) { if (!fields.containsKey("ID") || !fields.containsKey("SM")) throw new ParseException( "If you specify read group tags (RG) you must specify at least id and sample"); } return fields; }
From source file:MSUmpire.PSMDataStructure.FragmentSelection.java
public void GenerateProtPepScoreMap(float pepweight) { for (LCMSID IDSummary : FileList) { for (String key : IDSummary.ProteinList.keySet()) { if (!ProtPepScore.containsKey(key)) { ProtPepScore.put(key, new HashMap<String, Float>()); }//ww w . jav a 2 s . c o m } } for (String ProteinKey : ProtPepScore.keySet()) { HashMap<String, Float> pepscore = new HashMap<>(); HashMap<String, Integer> pepfreq = new HashMap<>(); int IDNo = 0; for (LCMSID IDSummary : FileList) { if (IDSummary.ProteinList.containsKey(ProteinKey)) { ProtID protein = IDSummary.ProteinList.get(ProteinKey); if (protein.IDByDBSearch) { IDNo++; } for (PepIonID pep : protein.PeptideID.values()) { if (pep.FilteringWeight > pepweight) { if (!pepscore.containsKey(pep.GetKey())) { pepscore.put(pep.GetKey(), 0f); pepfreq.put(pep.GetKey(), 0); } pepscore.put(pep.GetKey(), pepscore.get(pep.GetKey()) + pep.GetPepAbundanceByTopCorrFragAcrossSample(TopFrags.get(pep.GetKey()))); pepfreq.put(pep.GetKey(), pepfreq.get(pep.GetKey()) + 1); } } } } for (String pepkey : pepfreq.keySet()) { if (pepfreq.get(pepkey) > IDNo * freqPercent) { ProtPepScore.get(ProteinKey).put(pepkey, pepscore.get(pepkey)); } } } }
From source file:MSUmpire.PSMDataStructure.FragmentSelection.java
public void FillMissingFragScoreMap() { for (String PepKey : PepFragScore.keySet()) { if (PepFragScore.get(PepKey).isEmpty()) { HashMap<String, Float> fragmentscore = new HashMap<>(); for (LCMSID IDSummary : FileList) { PepIonID pep = null;// w ww .ja va 2 s . c o m if (IDSummary.GetPepIonList().containsKey(PepKey)) { pep = IDSummary.GetPepIonList().get(PepKey); } else if (IDSummary.GetMappedPepIonList().containsKey(PepKey)) { pep = IDSummary.GetMappedPepIonList().get(PepKey); } if (pep != null) { for (FragmentPeak frag : pep.FragmentPeaks) { if (!fragmentscore.containsKey(frag.GetFragKey())) { fragmentscore.put(frag.GetFragKey(), 0f); } fragmentscore.put(frag.GetFragKey(), fragmentscore.get(frag.GetFragKey()) + frag.corr * frag.intensity); if (!FragInt.containsKey(pep.GetKey() + "_" + frag.GetFragKey())) { FragInt.put(pep.GetKey() + "_" + frag.GetFragKey(), new HashMap<String, Float>()); } FragInt.get(pep.GetKey() + "_" + frag.GetFragKey()) .put(FilenameUtils.getBaseName(IDSummary.Filename), frag.intensity); } } } for (String fragkey : fragmentscore.keySet()) { PepFragScore.get(PepKey).put(fragkey, fragmentscore.get(fragkey)); } } } }
From source file:com.bah.applefox.main.plugins.imageindex.ImageAccumuloSampler.java
/** * Overridden method to create the sample *///from w w w. j a v a 2 s . c o m public void createSample() { try { // HashMap to write the sample table to HashMap<String, Integer> output = new HashMap<String, Integer>(); // Scan the data table Scanner scan = AccumuloUtils.connectRead(dataTable); Map<String, String> properties = new HashMap<String, String>(); IteratorSetting cfg2 = new IteratorSetting(11, SamplerCreator.class, properties); scan.addScanIterator(cfg2); for (Entry<Key, Value> entry : scan) { try { // Write the data from the table to the sample table String row = entry.getKey().getRow().toString(); int value = output.containsKey(row) ? output.get(row) : 0; value += 1; output.put(row, value); } catch (Exception e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } } // get the total number of docs from the urls table Scanner scann = AccumuloUtils.connectRead(urlTable); IteratorSetting cfg3 = new IteratorSetting(11, TotalDocFinder.class, properties); scann.addScanIterator(cfg3); for (Entry<Key, Value> entry : scann) { try { output.put(entry.getKey().getRow().toString(), (Integer) IngestUtils.deserialize(entry.getValue().get())); } catch (Exception e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } } // Create the sample table file System.out.println(output.size()); System.out.println("sample file: " + sampleFile); File f = new File(sampleFile); f.createNewFile(); // use buffering OutputStream file = new FileOutputStream(f); OutputStream buffer = new BufferedOutputStream(file); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(output); out.flush(); out.close(); } catch (AccumuloException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (AccumuloSecurityException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (TableNotFoundException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } catch (IOException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } } }