List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:pe.gob.mef.gescon.web.ui.ConsultaMB.java
public void filtrar(AjaxBehaviorEvent event) { HashMap filter = new HashMap(); try {/*from w w w . ja va 2 s . co m*/ filter.put("fCategoria", this.getCategoriesFilter()); filter.put("fFromDate", this.getFechaInicio()); filter.put("fToDate", this.getFechaFin()); filter.put("fType", this.getTypesFilter()); if (StringUtils.isNotBlank(this.getSearchText())) { HashMap map = Indexador.search(this.getSearchText()); filter.put("fCodesBL", (String) map.get("codesBL")); filter.put("fCodesPR", (String) map.get("codesPR")); filter.put("fCodesC", (String) map.get("codesC")); filter.put("fText", this.getSearchText().trim()); } else { filter.remove("fCodesBL"); filter.remove("fCodesPR"); filter.remove("fCodesC"); filter.remove("fText"); } filter.put("order", this.getOrdenpor()); ConsultaService service = (ConsultaService) ServiceFinder.findBean("ConsultaService"); this.setListaConsulta(service.getQueryFilter(filter)); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.ConsultaMB.java
public String search() { HashMap filter = new HashMap(); try {//from w w w . jav a2 s .c om filter.put("fCategoria", this.getCategoriesFilter()); filter.put("fFromDate", this.getFechaInicio()); filter.put("fToDate", this.getFechaFin()); filter.put("fType", this.getTypesFilter()); if (StringUtils.isNotBlank(this.getSearchText())) { HashMap map = Indexador.search(this.getSearchText()); filter.put("fCodesBL", (String) map.get("codesBL")); filter.put("fCodesPR", (String) map.get("codesPR")); filter.put("fCodesC", (String) map.get("codesC")); filter.put("fText", this.getSearchText().trim()); } else { filter.remove("fCodesBL"); filter.remove("fCodesPR"); filter.remove("fCodesC"); filter.remove("fText"); } filter.put("order", this.getOrdenpor()); ConsultaService service = (ConsultaService) ServiceFinder.findBean("ConsultaService"); this.setListaConsulta(service.getQueryFilter(filter)); if (CollectionUtils.isEmpty(this.getListaCategoriaFiltro())) { CategoriaService catservice = (CategoriaService) ServiceFinder.findBean("CategoriaService"); this.setListaCategoriaFiltro(catservice.getCategoriasActived()); createTree(this.getListaCategoriaFiltro()); this.setListaBreadCrumb(new ArrayList<Categoria>()); } if (CollectionUtils.isEmpty(this.getSelectedTipoConocimiento())) { TipoConocimientoService tcservice = (TipoConocimientoService) ServiceFinder .findBean("TipoConocimientoService"); this.setListaTipoConocimientoFiltro(tcservice.getTipoConocimientos()); } } catch (Exception e) { e.getMessage(); e.printStackTrace(); } return "/pages/consulta?faces-redirect=true"; }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testEntrySet() { HashMap<String, String> hashMap = new HashMap<String, String>(); checkEmptyHashMapAssumptions(hashMap); Set<Map.Entry<String, String>> entrySet = hashMap.entrySet(); assertNotNull(entrySet);/*from ww w .j a va 2s . c om*/ // Check that the entry set looks right hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_1); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); Iterator<Map.Entry<String, String>> itSet = entrySet.iterator(); Map.Entry<String, String> entry = itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_1); assertEmptyIterator(itSet); // Check that entries in the entrySet are update correctly on overwrites hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_2); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); itSet = entrySet.iterator(); entry = itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_2); assertEmptyIterator(itSet); // Check that entries are updated on removes hashMap.remove(KEY_TEST_ENTRY_SET); checkEmptyHashMapAssumptions(hashMap); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopMapFragment.java
/** * This method is called when the bus stops Loader has finished loading bus * stops and has data ready to be populated on the map. * /*from www. ja v a 2s . c o m*/ * @param result The data to be populated on the map. */ private void addBusStopMarkers(final HashMap<String, MarkerOptions> result) { if (map == null) { return; } // Get an array of the stopCodes that are currently on the map. This is // given to us as an array of Objects, which cannot be cast to an array // of Strings. final Object[] currentStops = busStopMarkers.keySet().toArray(); Marker marker; for (Object existingStop : currentStops) { marker = busStopMarkers.get((String) existingStop); // If the new data does not contain the given stopCode, and the // marker for that bus stop doesn't have an info window shown, then // remove it. if (!result.containsKey((String) existingStop) && !marker.isInfoWindowShown()) { marker.remove(); busStopMarkers.remove((String) existingStop); } else { // Otherwise, remove the bus stop from the new data as it is // already populated on the map and doesn't need to be // re-populated. This is a performance enhancement. result.remove((String) existingStop); } } // Loop through all the new bus stops, and add them to the map. Bus // stops common to the existing collection and the new collection will // not be touched. for (String newStop : result.keySet()) { busStopMarkers.put(newStop, map.addMarker(result.get(newStop))); } // If map has been moved to this location because the user searched for // a specific bus stop... if (searchedBusStop != null) { marker = busStopMarkers.get(searchedBusStop); // If the marker has been found... if (marker != null) { // Get the snippet text for the marker and if it does not exist, // populate it with the bus services list. final String snippet = marker.getSnippet(); if (snippet == null || snippet.length() == 0) { marker.setSnippet(bsd.getBusServicesForStopAsString(searchedBusStop)); } // Show the info window of the marker to highlight it. marker.showInfoWindow(); // Set this to null to make sure the stop isn't highlighted // again, until the user initiates another search. searchedBusStop = null; } } }
From source file:org.eclim.plugin.jdt.command.doc.CommentCommand.java
/** * Add or update the throws tags for the given method. * * @param javadoc The Javadoc instance.//from w ww. j av a 2 s . co m * @param method The method. * @param isNew true if we're adding to brand new javadocs. */ private void addUpdateThrowsTags(Javadoc javadoc, IMethod method, boolean isNew) throws Exception { @SuppressWarnings("unchecked") List<TagElement> tags = javadoc.tags(); // get thrown exceptions from element. String[] exceptions = method.getExceptionTypes(); if (isNew && exceptions.length > 0) { addTag(javadoc, tags.size(), null, null); for (int ii = 0; ii < exceptions.length; ii++) { addTag(javadoc, tags.size(), TagElement.TAG_THROWS, Signature.getSignatureSimpleName(exceptions[ii])); } } else { // get current throws tags HashMap<String, TagElement> current = new HashMap<String, TagElement>(); int index = tags.size(); for (int ii = tags.size() - 1; ii >= 0; ii--) { TagElement tag = (TagElement) tags.get(ii); if (TagElement.TAG_THROWS.equals(tag.getTagName())) { index = index == tags.size() ? ii + 1 : index; Name name = tag.fragments().size() > 0 ? (Name) tag.fragments().get(0) : null; if (name != null) { String text = name.getFullyQualifiedName(); String key = THROWS_PATTERN.matcher(text).replaceFirst("$1"); current.put(key, tag); } else { current.put(String.valueOf(ii), tag); } } // if we hit the return tag, a param tag, or the main text we can stop. if (TagElement.TAG_PARAM.equals(tag.getTagName()) || TagElement.TAG_RETURN.equals(tag.getTagName()) || tag.getTagName() == null) { break; } } // see what needs to be added / removed. for (int ii = 0; ii < exceptions.length; ii++) { String name = Signature.getSignatureSimpleName(exceptions[ii]); if (!current.containsKey(name)) { addTag(javadoc, index, TagElement.TAG_THROWS, name); } else { current.remove(name); } } // remove any left over thows clauses. for (TagElement tag : current.values()) { tags.remove(tag); } } }
From source file:org.sakaiproject.tool.assessment.ui.bean.author.AnswerBean.java
private List prepareItemTextAttachment(ItemTextIfc itemText, boolean isEditPendingAssessmentFlow) { ToolSession session = SessionManager.getCurrentToolSession(); if (session.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS) != null) { Set attachmentSet = new HashSet(); if (itemText != null) { attachmentSet = itemText.getItemTextAttachmentSet(); }/* w w w . j a v a 2 s .c om*/ HashMap map = getResourceIdHash(attachmentSet); ArrayList newAttachmentList = new ArrayList(); AssessmentService assessmentService = new AssessmentService(); String protocol = ContextUtil.getProtocol(); List refs = (List) session.getAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS); if (refs != null && refs.size() > 0) { Reference ref; for (int i = 0; i < refs.size(); i++) { ref = (Reference) refs.get(i); String resourceId = ref.getId(); if (map.get(resourceId) == null) { // new attachment, add log.debug("**** ref.Id=" + ref.getId()); log.debug("**** ref.name=" + ref.getProperties().getProperty(ref.getProperties().getNamePropDisplayName())); ItemTextAttachmentIfc newAttach = assessmentService.createItemTextAttachment(itemText, ref.getId(), ref.getProperties().getProperty(ref.getProperties().getNamePropDisplayName()), protocol, isEditPendingAssessmentFlow); newAttachmentList.add(newAttach); } else { // attachment already exist, let's add it to new list and // check it off from map newAttachmentList.add((ItemTextAttachmentIfc) map.get(resourceId)); map.remove(resourceId); } } } session.removeAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS); session.removeAttribute(FilePickerHelper.FILE_PICKER_CANCEL); return newAttachmentList; } else if (itemText == null) { return new ArrayList(); } else { ArrayList attachmentList = new ArrayList(); Set<ItemTextAttachmentIfc> itemTextAttachmentSet = itemText.getItemTextAttachmentSet(); for (Iterator<ItemTextAttachmentIfc> it = itemTextAttachmentSet.iterator(); it.hasNext();) { attachmentList.add(it.next()); } return attachmentList; } }
From source file:org.eclim.plugin.jdt.command.doc.CommentCommand.java
/** * Add or update the param tags for the given method. * * @param javadoc The Javadoc instance.// w w w. j av a 2s .c om * @param method The method. * @param isNew true if we're adding to brand new javadocs. */ private void addUpdateParamTags(Javadoc javadoc, IMethod method, boolean isNew) throws Exception { @SuppressWarnings("unchecked") List<TagElement> tags = javadoc.tags(); String[] params = method.getParameterNames(); if (isNew) { for (int ii = 0; ii < params.length; ii++) { addTag(javadoc, tags.size(), TagElement.TAG_PARAM, params[ii]); } } else { // find current params. int index = 0; HashMap<String, TagElement> current = new HashMap<String, TagElement>(); for (int ii = 0; ii < tags.size(); ii++) { TagElement tag = (TagElement) tags.get(ii); if (TagElement.TAG_PARAM.equals(tag.getTagName())) { if (current.size() == 0) { index = ii; } Object element = tag.fragments().size() > 0 ? tag.fragments().get(0) : null; if (element != null && element instanceof Name) { String name = ((Name) element).getFullyQualifiedName(); current.put(name, tag); } else { current.put(String.valueOf(ii), tag); } } else { if (current.size() > 0) { break; } if (tag.getTagName() == null) { index = ii + 1; } } } if (current.size() > 0) { for (int ii = 0; ii < params.length; ii++) { if (current.containsKey(params[ii])) { TagElement tag = (TagElement) current.get(params[ii]); int currentIndex = tags.indexOf(tag); if (currentIndex != ii) { tags.remove(tag); tags.add(index + ii, tag); } current.remove(params[ii]); } else { addTag(javadoc, index + ii, TagElement.TAG_PARAM, params[ii]); } } // remove any other param tags. for (TagElement tag : current.values()) { tags.remove(tag); } } else { for (int ii = 0; ii < params.length; ii++) { addTag(javadoc, index + ii, TagElement.TAG_PARAM, params[ii]); } } } }
From source file:opendap.aws.glacier.Vault.java
public void purgeDuplicates() throws IOException { VaultInventory inventory = getInventory(); HashMap<String, GlacierArchive> uniqueArchives = new HashMap<String, GlacierArchive>(); // Look at all the stuff in the inventory for (GlacierArchive gar : inventory.getArchiveList()) { gar.setVaultName(getVaultName()); String resourceID = gar.getResourceId(); // Have we encountered this resourceId? GlacierArchive uniqueArchive = uniqueArchives.get(resourceID); if (uniqueArchive == null) { // It's a new resourceID - add it to the uniqueArchives HashMap uniqueArchives.put(resourceID, gar); } else {/*from w w w . j a v a 2s. co m*/ // It's a resourceID we've already seen. Let's compare the creation dates _log.info("purgeDuplicates() - Found duplicate resourceID in vault."); _log.info("purgeDuplicates() - resourceID: {}", resourceID); _log.info("purgeDuplicates() - archiveID: {} creationDate{}", uniqueArchive.getArchiveId(), uniqueArchive.getCreationDate()); _log.info("purgeDuplicates() - archiveID: {} creationDate{}", gar.getArchiveId(), gar.getCreationDate()); if (uniqueArchive.getCreationDate().getTime() > gar.getCreationDate().getTime()) { // ah, the candidate archive was created before the current uniqueArchive // for this resourceID. Thus - delete it. deleteArchive(gar.getArchiveId()); } else { // Hmmm The new candidate archive was created after the current // unique archive for this resourceID. // Lets replace the uniqueArchive with the ewer one.. uniqueArchives.remove(resourceID); uniqueArchives.put(resourceID, gar); // And the delete the older one from the vault. deleteArchive(uniqueArchive.getArchiveId()); } } } }
From source file:com.ibm.bi.dml.hops.ipa.InterProceduralAnalysis.java
/** * /*w ww . j a v a2 s. com*/ * @param dmlp * @throws HopsException */ private void removeUnnecessaryCheckpoints(DMLProgram dmlp) throws HopsException { //approach: scan over top-level program (guaranteed to be unconditional), //collect checkpoints; determine if used before update; remove first checkpoint //on second checkpoint if update in between and not used before update HashMap<String, Hop> chkpointCand = new HashMap<String, Hop>(); for (StatementBlock sb : dmlp.getStatementBlocks()) { //prune candidates (used before updated) Set<String> cands = new HashSet<String>(chkpointCand.keySet()); for (String cand : cands) if (sb.variablesRead().containsVariable(cand) && !sb.variablesUpdated().containsVariable(cand)) { //note: variableRead might include false positives due to meta //data operations like nrow(X) or operations removed by rewrites //double check hops on basic blocks; otherwise worst-case boolean skipRemove = false; if (sb.get_hops() != null) { Hop.resetVisitStatus(sb.get_hops()); skipRemove = true; for (Hop root : sb.get_hops()) skipRemove &= !HopRewriteUtils.rContainsRead(root, cand, false); } if (!skipRemove) chkpointCand.remove(cand); } //prune candidates (updated in conditional control flow) Set<String> cands2 = new HashSet<String>(chkpointCand.keySet()); if (sb instanceof IfStatementBlock || sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock) { for (String cand : cands2) if (sb.variablesUpdated().containsVariable(cand)) { chkpointCand.remove(cand); } } //prune candidates (updated w/ multiple reads) else { for (String cand : cands2) if (sb.variablesUpdated().containsVariable(cand) && sb.get_hops() != null) { ArrayList<Hop> hops = sb.get_hops(); Hop.resetVisitStatus(hops); for (Hop root : hops) if (root.getName().equals(cand) && !HopRewriteUtils.rHasSimpleReadChain(root, cand)) { chkpointCand.remove(cand); } } } //collect checkpoints and remove unnecessary checkpoints ArrayList<Hop> tmp = collectCheckpoints(sb.get_hops()); for (Hop chkpoint : tmp) { if (chkpointCand.containsKey(chkpoint.getName())) { chkpointCand.get(chkpoint.getName()).setRequiresCheckpoint(false); } chkpointCand.put(chkpoint.getName(), chkpoint); } } }
From source file:org.apache.zeppelin.interpreter.InterpreterFactory.java
private void init() throws InterpreterException, IOException { ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); // Load classes File[] interpreterDirs = new File(conf.getInterpreterDir()).listFiles(); if (interpreterDirs != null) { for (File path : interpreterDirs) { logger.info("Reading " + path.getAbsolutePath()); URL[] urls = null;//w w w. ja v a 2s .com try { urls = recursiveBuildLibList(path); } catch (MalformedURLException e1) { logger.error("Can't load jars ", e1); } URLClassLoader ccl = new URLClassLoader(urls, oldcl); for (String className : interpreterClassList) { try { Class.forName(className, true, ccl); Set<String> keys = Interpreter.registeredInterpreters.keySet(); for (String intName : keys) { if (className.equals(Interpreter.registeredInterpreters.get(intName).getClassName())) { Interpreter.registeredInterpreters.get(intName).setPath(path.getAbsolutePath()); logger.info("Interpreter " + intName + " found. class=" + className); cleanCl.put(path.getAbsolutePath(), ccl); } } } catch (ClassNotFoundException e) { // nothing to do } } } } loadFromFile(); // if no interpreter settings are loaded, create default set synchronized (interpreterSettings) { if (interpreterSettings.size() == 0) { HashMap<String, List<RegisteredInterpreter>> groupClassNameMap = new HashMap<String, List<RegisteredInterpreter>>(); for (String k : Interpreter.registeredInterpreters.keySet()) { RegisteredInterpreter info = Interpreter.registeredInterpreters.get(k); if (!groupClassNameMap.containsKey(info.getGroup())) { groupClassNameMap.put(info.getGroup(), new LinkedList<RegisteredInterpreter>()); } groupClassNameMap.get(info.getGroup()).add(info); } for (String className : interpreterClassList) { for (String groupName : groupClassNameMap.keySet()) { List<RegisteredInterpreter> infos = groupClassNameMap.get(groupName); boolean found = false; Properties p = new Properties(); for (RegisteredInterpreter info : infos) { if (found == false && info.getClassName().equals(className)) { found = true; } for (String k : info.getProperties().keySet()) { p.put(k, info.getProperties().get(k).getDefaultValue()); } } if (found) { // add all interpreters in group add(groupName, groupName, defaultOption, p); groupClassNameMap.remove(groupName); break; } } } } } for (String settingId : interpreterSettings.keySet()) { InterpreterSetting setting = interpreterSettings.get(settingId); logger.info("Interpreter setting group {} : id={}, name={}", setting.getGroup(), settingId, setting.getName()); for (Interpreter interpreter : setting.getInterpreterGroup()) { logger.info(" className = {}", interpreter.getClassName()); } } }