List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:weave.servlets.GenericServlet.java
@SuppressWarnings("unchecked") private void handleServletRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from ww w .j a va 2 s .c om*/ ServletRequestInfo info = setServletRequestInfo(request, response); if (request.getMethod().equals("GET")) { List<String> urlParamNames = Collections.list(request.getParameterNames()); HashMap<String, String> params = new HashMap<String, String>(); for (String paramName : urlParamNames) params.put(paramName, request.getParameter(paramName)); JsonRpcRequestModel json = new JsonRpcRequestModel(); json.jsonrpc = JSONRPC_VERSION; json.id = ""; json.method = params.remove(METHOD); json.params = params; info.currentJsonRequest = json; invokeMethod(json.method, params); } else // post { try { String methodName; Object methodParams; if (info.inputStream.peek() == '[' || info.inputStream.peek() == '{') // json { handleArrayOfJsonRequests(info.inputStream, response); } else // AMF3 { ASObject obj = (ASObject) deserializeAmf3(info.inputStream); methodName = (String) obj.get(METHOD); methodParams = obj.get(PARAMS); info.streamParameterIndex = (Number) obj.get(STREAM_PARAMETER_INDEX); invokeMethod(methodName, methodParams); } } catch (IOException e) { sendError(e, null); } catch (Exception e) { sendError(e, null); } } handleJsonResponses(); } finally { removeServletRequestInfo(); } }
From source file:ilcc.ccgparser.incderivation.RevInc.java
private void updateMap(CCGJTreeNode curnode, CCGJTreeNode fnode, HashMap<Integer, CCGJTreeNode> map) { CCGJTreeNode node;// w ww. jav a 2 s. c om int lspan, rspan; lspan = curnode.getLSpan(); rspan = curnode.getRSpan(); for (int i = lspan; i <= rspan; i++) { if ((node = map.get(i)) != null) { map.remove(i); } } map.put(rspan, fnode); }
From source file:org.wso2.carbon.event.simulator.core.internal.CarbonEventSimulator.java
public void removeDataSourceTableAndStreamInfo(String datasourceConfigFileName) { int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (tenantSpecificDataSourceInfoMap.containsKey(tenantID)) { HashMap<String, DataSourceTableAndStreamInfo> dataSourceTableAndStreamInfoMap = tenantSpecificDataSourceInfoMap .get(tenantID);/*from w w w.j a va 2 s .co m*/ if (dataSourceTableAndStreamInfoMap != null) { dataSourceTableAndStreamInfoMap.remove(datasourceConfigFileName); } } }
From source file:org.jvoicexml.systemtest.mobicents.BroadcastServletDemo.java
protected void doRegister(SipServletRequest req) throws ServletException, IOException { VNXLog.info("Received register request: " + req.getTo()); int response = SipServletResponse.SC_OK; SipServletResponse resp = req.createResponse(response); HashMap<String, String> users = (HashMap<String, String>) getServletContext() .getAttribute("registeredUsersMap"); if (users == null) { users = new HashMap<String, String>(); }//www . ja va 2 s . c om getServletContext().setAttribute("registeredUsersMap", users); Address address = req.getAddressHeader(VAppCfg.CONTACT_HEADER); String fromURI = req.getFrom().getURI().toString(); int expires = address.getExpires(); if (expires < 0) { expires = req.getExpires(); } if (expires == 0) { users.remove(fromURI); VNXLog.info("User " + fromURI + " unregistered"); } else { resp.setAddressHeader(VAppCfg.CONTACT_HEADER, address); users.put(fromURI, address.getURI().toString()); VNXLog.info("User " + fromURI + " registered with an Expire time of " + expires); } resp.send(); }
From source file:it.cnr.icar.eric.server.lcm.LifeCycleManagerImpl.java
/** * Processes Associations looking for Associations that already exist and * are being submitted by source or target owner and are identical in state * to existing Association in registry./*from ww w. j a va 2 s .c o m*/ * * ebXML Registry 3.0 hasber discarded association confirmation in favour of * Role Based access control. However, freebXML Registry supports it in an * impl specific manner as this is required by JAXR 1.0 API. This SHOULD be * removed once JAXR 2.0 no longer requires it for ebXML Registry in future. * * The processing updates the Association to add a special Impl specific * slot to remember the confirmation state change. * * TODO: Need to do unconfirm when src or target owner removes an * Association they had previously confirmed. */ private void processConfirmationAssociations(ServerRequestContext context) throws RegistryException { try { // Make a copy to avoid ConcurrentModificationException ArrayList<?> topLevelObjects = new ArrayList<Object>( (context).getTopLevelRegistryObjectTypeMap().values()); Iterator<?> iter = topLevelObjects.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof AssociationType1) { AssociationType1 ass = (AssociationType1) obj; HashMap<String, Serializable> slotsMap = bu.getSlotsFromRegistryObject(ass); @SuppressWarnings("static-access") String beingConfirmed = (String) slotsMap.remove(bu.IMPL_SLOT_ASSOCIATION_IS_BEING_CONFIRMED); if ((beingConfirmed != null) && (beingConfirmed.equalsIgnoreCase("true"))) { // Need to set slotMap again ass.getSlot().clear(); bu.addSlotsToRegistryObject(ass, slotsMap); (context).getConfirmationAssociations().put(ass.getId(), ass); } } } } catch (javax.xml.bind.JAXBException e) { throw new RegistryException(e); } }
From source file:och.comp.paypal.standalone.PaypalPaymentsSynchService.java
protected void syncPaymentsByDate(List<PaymentExt> list, Date now) { if (isEmpty(list)) return;/*from ww w . ja v a 2 s.c o m*/ HashMap<String, PaymentExt> oldByIds = new HashMap<>(); Date minDate = null; for (PaymentExt p : list) { oldByIds.put(p.externalId, p); if (minDate == null || minDate.after(p.created)) minDate = p.created; } int daysBefore = (int) dateDiffInDays(now, minDate); if (daysBefore == 0) daysBefore = 1; List<PaymentBase> paymentHistory = null; try { paymentHistory = client.getPaymentHistory(daysBefore); } catch (Exception e) { addErrorToSend("can't getPaymentHistory: " + e); return; } if (isEmpty(paymentHistory)) { addErrorToSend("empty history by daysBefore: " + daysBefore + " for sync payments: " + list); return; } ; for (PaymentBase newItem : paymentHistory) { PaymentExt old = oldByIds.remove(newItem.externalId); if (old == null) continue; trySyncPayment(old, newItem, now); } }
From source file:de.dfki.km.perspecting.obie.model.Document.java
public List<TokenSequence<SemanticEntity>> getEntityTypes() { List<TokenSequence<SemanticEntity>> entities = new ArrayList<TokenSequence<SemanticEntity>>(); HashMap<Integer, TokenSequence<SemanticEntity>> map = new HashMap<Integer, TokenSequence<SemanticEntity>>(); for (int tokenIndex : this.data.getIntegerKeys(TokenSequence.TYPE)) { List<SemanticEntity> values = this.data.get(TokenSequence.TYPE, tokenIndex); if (values != null) { for (SemanticEntity value : values) { int property = value.getPropertyIndex(); if (value.getPosition().equals("B")) { TokenSequence<SemanticEntity> entity = map.get(property); if (entity != null) { entities.add(map.remove(property)); }/* w w w .ja v a2 s . c o m*/ entity = new TokenSequence<SemanticEntity>(value); entity.addToken(new Token(tokenIndex, this)); map.put(property, entity); } else { map.get(property).addToken(new Token(tokenIndex, this)); } } } else { entities.addAll(map.values()); map.clear(); } } entities.addAll(map.values()); return entities; }
From source file:com.google.gwt.emultest.java.util.HashMapTest.java
public void testKeysConflict() { HashMap<Object, String> hashMap = new HashMap<Object, String>(); hashMap.put(STRING_ZERO_KEY, STRING_ZERO_VALUE); hashMap.put(INTEGER_ZERO_KEY, INTEGER_ZERO_VALUE); hashMap.put(ODD_ZERO_KEY, ODD_ZERO_VALUE); assertEquals(hashMap.get(INTEGER_ZERO_KEY), INTEGER_ZERO_VALUE); assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); hashMap.remove(INTEGER_ZERO_KEY); assertEquals(hashMap.get(ODD_ZERO_KEY), ODD_ZERO_VALUE); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); hashMap.remove(ODD_ZERO_KEY);/*from w w w . ja v a 2s .c o m*/ assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); assertEquals(hashMap.get(ODD_ZERO_KEY), null); assertEquals(hashMap.get(STRING_ZERO_KEY), STRING_ZERO_VALUE); hashMap.remove(STRING_ZERO_KEY); assertEquals(hashMap.get(INTEGER_ZERO_KEY), null); assertEquals(hashMap.get(ODD_ZERO_KEY), null); assertEquals(hashMap.get(STRING_ZERO_KEY), null); assertEquals(hashMap.size(), 0); }
From source file:com.google.sampling.experiential.server.EventServlet.java
public void postEventFromRowAsHash(HashMap<String, String> rowData, boolean isDevInstance) throws ParseException { User loggedInWho = getWhoFromLogin(); if (loggedInWho == null) { throw new IllegalArgumentException("Must be logged in!"); }/* w w w. j a v a 2 s . c o m*/ String who = loggedInWho.getEmail(); String whoFromPost = null; if (rowData.containsKey("who")) { whoFromPost = rowData.get("who"); rowData.remove("who"); } if (isDevInstance && whoFromPost != null) { who = whoFromPost; } String lat = null; String lon = null; String where = null; if (rowData.containsKey("where")) { where = rowData.get("where"); rowData.remove("where"); lat = where.substring(0, where.indexOf(",")); lon = where.substring(where.indexOf(",") + 1); } String appId = "from_csv"; if (rowData.containsKey("appId")) { appId = rowData.get("appId"); rowData.remove("appId"); } String pacoVersion = null; if (rowData.containsKey("pacoVersion")) { pacoVersion = rowData.get("pacoVersion"); rowData.remove("pacoVersion"); } SimpleDateFormat df = new SimpleDateFormat(TimeUtil.DATETIME_FORMAT); SimpleDateFormat oldDf = new SimpleDateFormat(TimeUtil.DATETIME_FORMAT_OLD); Date whenDate = null; if (rowData.containsKey("when")) { String when = rowData.get("when"); rowData.remove("when"); whenDate = parseDate(df, oldDf, when); } else { whenDate = new Date(); } boolean shared = false; String experimentId = null; String experimentName = null; Date responseTime = null; Date scheduledTime = null; if (rowData.containsKey("experimentId")) { experimentId = rowData.get("experimentId"); rowData.remove("experimentId"); } if (rowData.containsKey("experimentName")) { experimentName = rowData.get("experimentName"); rowData.remove("experimentName"); } Experiment experiment = ExperimentRetriever.getExperiment(experimentId); if (experiment == null) { throw new IllegalArgumentException("Must post to an existing experiment!"); } if (!ExperimentRetriever.isWhoAllowedToPostToExperiment(experiment, who)) { throw new IllegalArgumentException("This user is not allowed to post to this experiment"); } Set<What> whats = Sets.newHashSet(); List<PhotoBlob> blobs = Lists.newArrayList(); if (rowData.keySet().size() > 0) { log.info("There are " + rowData.keySet().size() + " csv columns left"); for (String name : rowData.keySet()) { String answer = rowData.get(name); Input input = null; if (experiment != null) { input = experiment.getInputWithName(name); } if (input != null && input.getResponseType() != null && input.getResponseType().equals(InputDAO.PHOTO)) { PhotoBlob photoBlob = new PhotoBlob(name, Base64.decodeBase64(answer.getBytes())); blobs.add(photoBlob); answer = "blob"; } whats.add(new What(name, answer)); } } if (rowData.containsKey("responseTime")) { String responseTimeStr = rowData.get("responseTime"); if (!responseTimeStr.equals("null") && !responseTimeStr.isEmpty()) { responseTime = parseDate(df, oldDf, responseTimeStr); } } if (rowData.containsKey("scheduledTime")) { String timeStr = rowData.get("scheduledTime"); if (!timeStr.equals("null") && !timeStr.isEmpty()) { scheduledTime = parseDate(df, oldDf, timeStr); } } log.info("Sanity check: who = " + who + ", when = " + (new SimpleDateFormat(TimeUtil.DATETIME_FORMAT)).format(whenDate) + ", appId = " + appId + ", what length = " + whats.size()); EventRetriever.getInstance().postEvent(who, lat, lon, whenDate, appId, pacoVersion, whats, shared, experimentId, experimentName, responseTime, scheduledTime, blobs); }
From source file:gov.nih.nci.cabig.caaers.web.admin.UserAjaxFacade.java
/** * This method is invoked from the user_search.jsp to fetch csm users for the given search criteria * @param searchCriteriaMap/*from w ww . j a v a 2s . c o m*/ * @return */ @SuppressWarnings("unchecked") public List<UserAjaxableDomainObject> getUserTable(HashMap searchCriteriaMap) { List<UserAjaxableDomainObject> ajaxableUserList = new ArrayList<UserAjaxableDomainObject>(); if (!StringUtils.equals("person", (String) searchCriteriaMap.get("linkType"))) { String name = (String) searchCriteriaMap.get("name"); String fName = (String) searchCriteriaMap.get("firstName"); String lName = (String) searchCriteriaMap.get("lastName"); String uName = (String) searchCriteriaMap.get("userName"); List<gov.nih.nci.security.authorization.domainobjects.User> csmUserList; if (StringUtils.isEmpty(name)) { csmUserList = userRepository.searchCsmUser(fName, lName, uName); } else { csmUserList = userRepository.searchCsmUser(name); } if (StringUtils.equals("user", (String) searchCriteriaMap.get("linkType"))) { if (CollectionUtils.isNotEmpty(csmUserList)) { HashMap<String, gov.nih.nci.security.authorization.domainobjects.User> userMap = new HashMap<String, gov.nih.nci.security.authorization.domainobjects.User>(); for (gov.nih.nci.security.authorization.domainobjects.User csmUser : csmUserList) { userMap.put(csmUser.getLoginName(), csmUser); } ResearchStaffQuery rsQuery = new ResearchStaffQuery(); rsQuery.filterByExactLoginId(userMap.keySet().toArray(new String[] {})); rsQuery.setFiltered(true); List<ResearchStaff> staffs = personRepository.searchLocalResearchStaff(rsQuery); for (ResearchStaff rs : staffs) { userMap.remove(rs.getLoginId()); } InvestigatorQuery invQuery = new InvestigatorQuery(); invQuery.filterByExactLoginId(userMap.keySet().toArray(new String[] {})); invQuery.setFiltered(true); List<Investigator> investigators = personRepository.searchLocalInvestigator(invQuery); for (Investigator inv : investigators) { userMap.remove(inv.getLoginId()); } csmUserList = new ArrayList<gov.nih.nci.security.authorization.domainobjects.User>( userMap.values()); } } UserAjaxableDomainObject ajaxableUser = null; for (gov.nih.nci.security.authorization.domainobjects.User csmUser : csmUserList) { ajaxableUser = new UserAjaxableDomainObject(); ajaxableUser.setId(csmUser.getUserId().intValue()); ajaxableUser.setFirstName(csmUser.getFirstName()); ajaxableUser.setLastName(csmUser.getLastName()); ajaxableUser.setMiddleName(""); ajaxableUser.setNumber(""); ajaxableUser.setExternalId(""); ajaxableUser.setUserName(csmUser.getLoginName()); ajaxableUser.setEmailAddress(csmUser.getEmailId()); ajaxableUser.setRecordType("CSM_RECORD"); if (csmUser.getEndDate() != null) { ajaxableUser.setLocked( DateUtils.compareDate(csmUser.getEndDate(), Calendar.getInstance().getTime()) <= 0); } ajaxableUserList.add(ajaxableUser); } } return ajaxableUserList; }