List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java
protected EditProcessObject createEpo(HttpServletRequest request, boolean forceNew) { /* this is actually a bit of a misnomer, because we will reuse an epo if an epoKey parameter is passed */ EditProcessObject epo = null;/*from www . j a v a2s .c o m*/ HashMap epoHash = getEpoHash(request); String existingEpoKey = request.getParameter("_epoKey"); if (!forceNew && existingEpoKey != null && epoHash.get(existingEpoKey) != null) { epo = (EditProcessObject) epoHash.get(existingEpoKey); epo.setKey(existingEpoKey); epo.setUseRecycledBean(true); } else { LinkedList epoKeylist = getEpoKeylist(request); if (epoHash.size() == MAX_EPOS) { try { epoHash.remove(epoKeylist.getFirst()); epoKeylist.removeFirst(); } catch (Exception e) { // see JIRA issue VITRO-340, "Odd exception from backend editing" // possible rare concurrency issue here log.error("Error removing old EPO", e); } } Random rand = new Random(); String epoKey = createEpoKey(); while (epoHash.get(epoKey) != null) { epoKey += Integer.toHexString(rand.nextInt()); } epo = new EditProcessObject(); epoHash.put(epoKey, epo); epoKeylist.add(epoKey); epo.setKey(epoKey); epo.setReferer( (forceNew) ? request.getRequestURL().append('?').append(request.getQueryString()).toString() : request.getHeader("Referer")); epo.setSession(request.getSession()); } return epo; }
From source file:gov.nih.nci.cabig.caaers.service.synchronizer.StudyDiseasesSynchronizer.java
public void migrate(Study dbStudy, Study xmlStudy, DomainObjectImportOutcome<Study> outcome) { //ignore if disease section is empty in xmlstudy if (CollectionUtils.isEmpty(xmlStudy.getActiveStudyDiseases())) { return;//from ww w . ja v a2s . c o m } //create an Index of existing study diseases HashMap<AbstractStudyDisease<? extends DomainObject>, AbstractStudyDisease<? extends DomainObject>> dbDiseasesIndexMap = new HashMap<AbstractStudyDisease<? extends DomainObject>, AbstractStudyDisease<? extends DomainObject>>(); for (AbstractStudyDisease<? extends DomainObject> studyDisease : dbStudy.getActiveStudyDiseases()) { dbDiseasesIndexMap.put(studyDisease, studyDisease); } //loop through the xml study, then add/update existing diseases for (AbstractStudyDisease<? extends DomainObject> xmlDisease : xmlStudy.getActiveStudyDiseases()) { AbstractStudyDisease<? extends DomainObject> disease = dbDiseasesIndexMap.remove(xmlDisease); if (disease == null) { //new disease, so add to dbstudy if (xmlDisease instanceof CtepStudyDisease) dbStudy.addCtepStudyDisease((CtepStudyDisease) xmlDisease); if (xmlDisease instanceof MeddraStudyDisease) dbStudy.addMeddraStudyDisease((MeddraStudyDisease) xmlDisease); if (xmlDisease instanceof StudyCondition) dbStudy.addStudyCondition((StudyCondition) xmlDisease); continue; } //update the primary indicator (if CTEP Disease) if (disease instanceof CtepStudyDisease) { ((CtepStudyDisease) disease).setLeadDisease(((CtepStudyDisease) xmlDisease).getLeadDisease()); } } //mark retired the diseases still in index AbstractMutableRetireableDomainObject.retire(dbDiseasesIndexMap.values()); }
From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java
private void createDataSet() throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(this.filePath))); String line = null;// w ww. j a v a 2 s . c o m String name = null; int number = 0; HashMap<Integer, String> map = new HashMap<Integer, String>(); String[][] tempS = new String[100][2]; int lineNo = 0; while ((line = reader.readLine()) != null) { String[] sg = line.split(","); name = sg[0]; number = Integer.parseInt(sg[1]); tempS[lineNo][0] = name; tempS[lineNo][1] = sg[1]; // if (map.containsKey(number)) { String temp = map.get(number); map.remove(number); map.put(number, temp + ", " + name); } else { map.put(number, name); } lineNo++; } // load pie data data1 = new DefaultPieDataset(); Set<Integer> keys = map.keySet(); for (Integer key : keys) { data1.setValue(key + " times: " + map.get(key), key); } // load table data data2 = new String[lineNo + 1][2]; data2[0][0] = "Name"; data2[0][1] = "Reuse Times"; for (int i = 0; i < lineNo; i++) { data2[i + 1] = tempS[i]; } reader.close(); }
From source file:org.wso2.andes.server.security.SecurityManager.java
private boolean checkAllPlugins(AccessCheck checker) { HashMap<String, SecurityPlugin> remainingPlugins = new HashMap<String, SecurityPlugin>(_globalPlugins); for (Entry<String, SecurityPlugin> hostEntry : _hostPlugins.entrySet()) { // Create set of global only plugins SecurityPlugin globalPlugin = remainingPlugins.get(hostEntry.getKey()); if (globalPlugin != null) { remainingPlugins.remove(hostEntry.getKey()); }/*from ww w . j a v a2s .co m*/ Result host = checker.allowed(hostEntry.getValue()); if (host == Result.DENIED) { // Something vetoed the access, we're done return false; } // host allow overrides global allow, so only check global on abstain or defer if (host != Result.ALLOWED) { if (globalPlugin == null) { if (host == Result.DEFER) { host = hostEntry.getValue().getDefault(); } if (host == Result.DENIED) { return false; } } else { Result global = checker.allowed(globalPlugin); if (global == Result.DEFER) { global = globalPlugin.getDefault(); } if (global == Result.ABSTAIN && host == Result.DEFER) { global = hostEntry.getValue().getDefault(); } if (global == Result.DENIED) { return false; } } } } for (SecurityPlugin plugin : remainingPlugins.values()) { Result remaining = checker.allowed(plugin); if (remaining == Result.DEFER) { remaining = plugin.getDefault(); } if (remaining == Result.DENIED) { return false; } } // getting here means either allowed or abstained from all plugins return true; }
From source file:FastHashMap.java
/** * Remove any mapping for this key, and return any previously * mapped value./* ww w. j a v a 2s . co m*/ * * @param key the key whose mapping is to be removed * @return the value removed, or null */ public Object remove(Object key) { if (fast) { synchronized (this) { HashMap temp = (HashMap) map.clone(); Object result = temp.remove(key); map = temp; return (result); } } else { synchronized (map) { return (map.remove(key)); } } }
From source file:com.shizhefei.view.multitype.MultiTypeAdapter.java
private List<ItemBinder<ITEM_DATA>> toItemData(@NonNull List<? extends ITEM_DATA> addList, boolean refresh) { HashMap<? extends ITEM_DATA, ItemBinder<ITEM_DATA>> removeItemData = null; if (refresh) { removeItemData = data_Providers; data_Providers = new HashMap<>(); }/*from ww w . j ava 2 s .c o m*/ List<ItemBinder<ITEM_DATA>> providers = new ArrayList<>(addList.size()); for (ITEM_DATA object : addList) { ItemBinder<ITEM_DATA> itemBinder; if (refresh) { itemBinder = removeItemData.remove(object); } else { itemBinder = data_Providers.get(object); } if (itemBinder == null) { itemBinder = factory.buildItemData(object); } data_Providers.put(object, itemBinder); providers.add(itemBinder); providerIndex.put(itemBinder.providerType, itemBinder.provider); } if (refresh) { //?Fragment doRemoveItemData(removeItemData.values()); } return providers; }
From source file:org.sakaiproject.tool.assessment.ui.listener.evaluation.StudentScoreUpdateListener.java
public void updateAttachment(DeliveryBean delivery) { ArrayList parts = delivery.getPageContents().getPartsContents(); Iterator iter = parts.iterator(); List attachmentList = new ArrayList(); while (iter.hasNext()) { ArrayList items = ((SectionContentsBean) iter.next()).getItemContents(); Iterator iter2 = items.iterator(); while (iter2.hasNext()) { ItemContentsBean question = (ItemContentsBean) iter2.next(); List<ItemGradingData> gradingarray = question.getItemGradingDataArray(); log.debug("Gradingarray length2 = " + gradingarray.size()); Iterator<ItemGradingData> iter3 = gradingarray.iterator(); while (iter3.hasNext()) { ItemGradingData itemGradingData = iter3.next(); List oldList = itemGradingData.getItemGradingAttachmentList(); List newList = question.getItemGradingAttachmentList(); if ((oldList == null || oldList.size() == 0) && (newList == null || newList.size() == 0)) { continue; }/* w w w. j av a2 s. c om*/ HashMap map = getAttachmentIdHash(oldList); for (int i = 0; i < newList.size(); i++) { ItemGradingAttachment itemGradingAttachment = (ItemGradingAttachment) newList.get(i); if (map.get(itemGradingAttachment.getAttachmentId()) != null) { // exist already, remove it from map map.remove(itemGradingAttachment.getAttachmentId()); } else { // new attachments itemGradingAttachment.setItemGrading(itemGradingData); attachmentList.add(itemGradingAttachment); } } // save new ones GradingService gradingService = new GradingService(); if (attachmentList.size() > 0) { gradingService.saveOrUpdateAttachments(attachmentList); EventTrackingService.post(EventTrackingService.newEvent("sam.student.score.update", "siteId=" + AgentFacade.getCurrentSiteId() + ", Adding " + attachmentList.size() + " attachments for itemGradingData id = " + itemGradingData.getItemGradingId(), true)); } // remove old ones Set set = map.keySet(); Iterator iter4 = set.iterator(); while (iter4.hasNext()) { Long attachmentId = (Long) iter4.next(); gradingService.removeItemGradingAttachment(attachmentId.toString()); EventTrackingService.post(EventTrackingService.newEvent("sam.student.score.update", "siteId=" + AgentFacade.getCurrentSiteId() + ", Removing attachmentId = " + attachmentId, true)); } } } } }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync.java
/** * Loads the remote lists from the database and merges the two lists. If the * remote list contains all lists, then this method only adds local db-ids * to the items. If it does not contain all of them, this loads whatever * extra items are known in the db to the list also. * //from w ww.ja va 2s . c o m * Since all lists are expected to be downloaded, any non-existing entries * are assumed to be deleted and marked as such. */ public static void mergeListsWithLocalDB(final Context context, final String account, final List<GoogleTaskList> remoteLists) { Log.d(TAG, "mergeList starting with: " + remoteLists.size()); final HashMap<String, GoogleTaskList> localVersions = new HashMap<String, GoogleTaskList>(); final Cursor c = context.getContentResolver().query(GoogleTaskList.URI, GoogleTaskList.Columns.FIELDS, GoogleTaskList.Columns.ACCOUNT + " IS ? AND " + GoogleTaskList.Columns.SERVICE + " IS ?", new String[] { account, GoogleTaskList.SERVICENAME }, null); try { while (c.moveToNext()) { GoogleTaskList list = new GoogleTaskList(c); localVersions.put(list.remoteId, list); } } finally { if (c != null) c.close(); } for (final GoogleTaskList remotelist : remoteLists) { // Merge with hashmap if (localVersions.containsKey(remotelist.remoteId)) { //Log.d(TAG, "Setting merge id"); remotelist.dbid = localVersions.get(remotelist.remoteId).dbid; //Log.d(TAG, "Setting merge delete status"); remotelist.setDeleted(localVersions.get(remotelist.remoteId).isDeleted()); localVersions.remove(remotelist.remoteId); } } // Remaining ones for (final GoogleTaskList list : localVersions.values()) { list.remotelyDeleted = true; remoteLists.add(list); } Log.d(TAG, "mergeList finishing with: " + remoteLists.size()); }
From source file:org.carrot2.core.Document.java
@ElementMap(entry = "field", key = "key", attribute = true, inline = true, required = false) private HashMap<String, SimpleXmlWrapperValue> getOtherFieldsXml() { final HashMap<String, SimpleXmlWrapperValue> otherFieldsForSerialization; synchronized (this) { otherFieldsForSerialization = MapUtils.asHashMap(SimpleXmlWrappers.wrap(fields)); }//from w w w.j ava 2 s. c om otherFieldsForSerialization.remove(TITLE); otherFieldsForSerialization.remove(SUMMARY); otherFieldsForSerialization.remove(CONTENT_URL); otherFieldsForSerialization.remove(SOURCES); otherFieldsForSerialization.remove(LANGUAGE); otherFieldsForSerialization.remove(SCORE); fireSerializationListeners(otherFieldsForSerialization); return otherFieldsForSerialization.isEmpty() ? null : otherFieldsForSerialization; }
From source file:org.wso2.carbon.event.simulator.core.CSVFileDeployer.java
public void processUndeploy(String filePath) throws DeploymentException { CarbonEventSimulator eventSimulator = EventSimulatorValueHolder.getEventSimulator(); HashMap<String, CSVFileInfo> csvFileInfoMap = eventSimulator.getCSVFileInfoMap(); File csvFile = new File(filePath); CSVFileInfo csvFileInfo = csvFileInfoMap.get(csvFile.getName()); String repo = configurationContext.getAxisConfiguration().getRepository().getPath(); String path = repo + EventSimulatorConstant.DEPLOY_DIRECTORY_PATH; String xmlFileName = csvFileInfo.getFileName().substring(0, csvFileInfo.getFileName().length() - 4) + EventSimulatorConstant.CONFIGURATION_XML_SUFFIX; String xmlFilePath = path + File.separator + xmlFileName; File xmlFile = new File(xmlFilePath); csvFileInfoMap.remove(csvFile.getName()); if (xmlFile.exists()) { if (!xmlFile.delete()) { int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); throw new DeploymentException(xmlFileName + " could not be deleted for tenant ID : " + tenantID); }// ww w. java 2 s. c o m } log.info("CSV file " + csvFile.getName() + " undeployed successfully."); }