List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:opendap.threddsHandler.ThreddsCatalogUtil.java
private HashMap<String, Element> collectServices(Element threddsCatalog, SERVICE s) throws InterruptedException { HashMap<String, Element> services = collectServices(threddsCatalog); HashMap<String, Element> childSrvcs; // If they aren't asking for everything... if (s != SERVICE.ALL) { /* boolean done = false; */ Element service;/*from w ww .j a v a 2 s.c o m*/ Vector<String> taggedForRemoval = new Vector<String>(); for (String serviceName : services.keySet()) { service = services.get(serviceName); if (service.getAttributeValue("serviceType").equalsIgnoreCase(SERVICE.Compound.toString())) { childSrvcs = collectServices(service, s); if (childSrvcs.isEmpty()) { taggedForRemoval.add(serviceName); } } else if (!service.getAttributeValue("serviceType").equalsIgnoreCase(s.toString())) { taggedForRemoval.add(serviceName); } } for (String serviceName : taggedForRemoval) { services.remove(serviceName); } } return services; }
From source file:oscar.oscarRx.util.RxUtil.java
private static List<HashMap<String, String>> commonUniqueMedHistory(List<HashMap<String, String>> l) { MiscUtils.getLogger().debug("in commonUniqueMedHistory l=" + l); if (l != null && l.size() > 0) { HashMap elementCount = new HashMap(); List<HashMap<String, String>> retList = new ArrayList(); for (HashMap<String, String> hm : l) { if (!elementCount.containsKey(hm)) elementCount.put(hm, 1); else/*from w w w . ja va 2 s .co m*/ elementCount.put(hm, (Integer) elementCount.get(hm) + 1); } List<Integer> count = new ArrayList(elementCount.values()); HashMap[] arr = new HashMap[count.size()]; Collections.sort(count);//ascending order try { for (int i = count.size() - 1; i >= 0; i--) { Set set = elementCount.keySet(); Iterator iter = set.iterator(); while (iter.hasNext()) { HashMap key = (HashMap) iter.next(); Integer value = (Integer) elementCount.get(key); if (value == count.get(i)) { retList.add(key); elementCount.remove(key); break; } else ; } } } catch (Exception e) { MiscUtils.getLogger().error("Error", e); } MiscUtils.getLogger().debug("in commonUniqueMedHistory retList=" + retList); return retList; } else return l; }
From source file:com.android.exchange.SyncManager.java
/** * Sent by services indicating that their thread is finished; action depends on the exitStatus * of the service./*from w ww . j ava 2s. com*/ * * @param svc the service that is finished */ static public void done(AbstractSyncService svc) { SyncManager syncManager = INSTANCE; if (syncManager == null) return; synchronized (sSyncLock) { long mailboxId = svc.mMailboxId; HashMap<Long, SyncError> errorMap = syncManager.mSyncErrorMap; SyncError syncError = errorMap.get(mailboxId); syncManager.releaseMailbox(mailboxId); int exitStatus = svc.mExitStatus; switch (exitStatus) { case AbstractSyncService.EXIT_DONE: if (!svc.mRequests.isEmpty()) { // TODO Handle this case } errorMap.remove(mailboxId); // If we've had a successful sync, clear the shutdown count synchronized (SyncManager.class) { sClientConnectionManagerShutdownCount = 0; } break; // I/O errors get retried at increasing intervals case AbstractSyncService.EXIT_IO_ERROR: Mailbox m = Mailbox.restoreMailboxWithId(syncManager, mailboxId); if (m == null) return; if (syncError != null) { syncError.escalate(); log(m.mDisplayName + " held for " + syncError.holdDelay + "ms"); } else { errorMap.put(mailboxId, syncManager.new SyncError(exitStatus, false)); log(m.mDisplayName + " added to syncErrorMap, hold for 15s"); } break; // These errors are not retried automatically case AbstractSyncService.EXIT_SECURITY_FAILURE: case AbstractSyncService.EXIT_LOGIN_FAILURE: case AbstractSyncService.EXIT_EXCEPTION: errorMap.put(mailboxId, syncManager.new SyncError(exitStatus, true)); break; } kick("sync completed"); } }
From source file:org.kuali.rice.kim.impl.identity.PersonServiceImpl.java
public Map<String, String> convertPersonPropertiesToEntityProperties(Map<String, String> criteria) { if (LOG.isDebugEnabled()) { LOG.debug("convertPersonPropertiesToEntityProperties: " + criteria); }//from w ww . jav a 2 s . co m boolean nameCriteria = false; boolean addressCriteria = false; boolean externalIdentifierCriteria = false; boolean affiliationCriteria = false; boolean affiliationDefaultOnlyCriteria = false; boolean phoneCriteria = false; boolean emailCriteria = false; boolean employeeIdCriteria = false; // add base lookups for all person lookups HashMap<String, String> newCriteria = new HashMap<String, String>(); newCriteria.putAll(baseLookupCriteria); newCriteria.put("entityTypeContactInfos.entityTypeCode", personEntityTypeLookupCriteria); if (criteria != null) { for (String key : criteria.keySet()) { //check active radio button if (key.equals(KIMPropertyConstants.Person.ACTIVE)) { newCriteria.put(criteriaConversion.get(KIMPropertyConstants.Person.ACTIVE), criteria.get(KIMPropertyConstants.Person.ACTIVE)); } else { // The following if statement enables the "both" button to work correctly. if (!(criteria.containsKey(KIMPropertyConstants.Person.ACTIVE))) { newCriteria.remove(KIMPropertyConstants.Person.ACTIVE); } } // if no value was passed, skip the entry in the Map if (StringUtils.isEmpty(criteria.get(key))) { continue; } // check if the value needs to be encrypted // handle encrypted external identifiers if (key.equals(KIMPropertyConstants.Person.EXTERNAL_ID) && StringUtils.isNotBlank(criteria.get(key))) { // look for a ext ID type property if (criteria.containsKey(KIMPropertyConstants.Person.EXTERNAL_IDENTIFIER_TYPE_CODE)) { String extIdTypeCode = criteria .get(KIMPropertyConstants.Person.EXTERNAL_IDENTIFIER_TYPE_CODE); if (StringUtils.isNotBlank(extIdTypeCode)) { // if found, load that external ID Type via service EntityExternalIdentifierType extIdType = getIdentityService() .getExternalIdentifierType(extIdTypeCode); // if that type needs to be encrypted, encrypt the value in the criteria map if (extIdType != null && extIdType.isEncryptionRequired()) { try { if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { criteria.put(key, CoreApiServiceLocator.getEncryptionService() .encrypt(criteria.get(key))); } } catch (GeneralSecurityException ex) { LOG.error("Unable to encrypt value for external ID search of type " + extIdTypeCode, ex); } } } } } // convert the property to the Entity data model String entityProperty = criteriaConversion.get(key); if (entityProperty != null) { newCriteria.put(entityProperty, criteria.get(key)); } else { entityProperty = key; // just pass it through if no translation present newCriteria.put(key, criteria.get(key)); } // check if additional criteria are needed based on the types of properties specified if (isNameEntityCriteria(entityProperty)) { nameCriteria = true; } if (isExternalIdentifierEntityCriteria(entityProperty)) { externalIdentifierCriteria = true; } if (isAffiliationEntityCriteria(entityProperty)) { affiliationCriteria = true; } if (isAddressEntityCriteria(entityProperty)) { addressCriteria = true; } if (isPhoneEntityCriteria(entityProperty)) { phoneCriteria = true; } if (isEmailEntityCriteria(entityProperty)) { emailCriteria = true; } if (isEmployeeIdEntityCriteria(entityProperty)) { employeeIdCriteria = true; } // special handling for the campus code, since that forces the query to look // at the default affiliation record only if (key.equals("campusCode")) { affiliationDefaultOnlyCriteria = true; } } if (nameCriteria) { newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "defaultValue", "Y"); //newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "nameCode", "PRFR");//so we only display 1 result } if (addressCriteria) { newCriteria.put(ENTITY_ADDRESS_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_ADDRESS_PROPERTY_PREFIX + "defaultValue", "Y"); } if (phoneCriteria) { newCriteria.put(ENTITY_PHONE_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_PHONE_PROPERTY_PREFIX + "defaultValue", "Y"); } if (emailCriteria) { newCriteria.put(ENTITY_EMAIL_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_EMAIL_PROPERTY_PREFIX + "defaultValue", "Y"); } if (employeeIdCriteria) { newCriteria.put(ENTITY_EMPLOYEE_ID_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_EMPLOYEE_ID_PROPERTY_PREFIX + "primary", "Y"); } if (affiliationCriteria) { newCriteria.put(ENTITY_AFFILIATION_PROPERTY_PREFIX + "active", "Y"); } if (affiliationDefaultOnlyCriteria) { newCriteria.put(ENTITY_AFFILIATION_PROPERTY_PREFIX + "defaultValue", "Y"); } } if (LOG.isDebugEnabled()) { LOG.debug("Converted: " + newCriteria); } return newCriteria; }
From source file:org.opencastproject.archive.opencast.solr.SolrIndexManager.java
/** * Generates a string with the most important kewords from the text annotation. * //from w w w .ja va 2 s .co m * @param sortedAnnotations * @return The keyword string. */ static StringBuffer importantKeywordsString(SortedSet<TextAnnotation> sortedAnnotations) { // important keyword: // - high relevance // - high confidence // - occur often // - more than MAX_CHAR chars // calculate keyword occurences (histogram) and importance ArrayList<String> list = new ArrayList<String>(); Iterator<TextAnnotation> textAnnotations = sortedAnnotations.iterator(); TextAnnotation textAnnotation = null; String keyword = null; HashMap<String, Integer> histogram = new HashMap<String, Integer>(); HashMap<String, Double> importance = new HashMap<String, Double>(); int occ = 0; double imp; while (textAnnotations.hasNext()) { textAnnotation = textAnnotations.next(); Iterator<KeywordAnnotation> keywordAnnotations = textAnnotation.keywordAnnotations(); while (keywordAnnotations.hasNext()) { KeywordAnnotation annotation = keywordAnnotations.next(); keyword = annotation.getKeyword().toLowerCase(); if (keyword.length() > MAX_CHAR) { occ = 0; if (histogram.keySet().contains(keyword)) { occ = histogram.get(keyword); } histogram.put(keyword, occ + 1); // here the importance value is calculated // from relevance, confidence and frequency of occurence. imp = (RELEVANCE_BOOST * getMaxRelevance(keyword, sortedAnnotations) + getMaxConfidence(keyword, sortedAnnotations)) * (occ + 1); importance.put(keyword, imp); } } } // get the MAX_IMPORTANT_COUNT most important keywords StringBuffer buf = new StringBuffer(); while (list.size() < MAX_IMPORTANT_COUNT && importance.size() > 0) { double max = 0.0; String maxKeyword = null; // get maximum from importance list for (Entry<String, Double> entry : importance.entrySet()) { keyword = entry.getKey(); if (max < entry.getValue()) { max = entry.getValue(); maxKeyword = keyword; } } // pop maximum importance.remove(maxKeyword); // append keyword to string if (buf.length() > 0) buf.append(" "); buf.append(maxKeyword); } return buf; }
From source file:org.easyrec.plugin.container.PluginRegistry.java
public void installDefaultOnFirstRun() throws Exception { if (properties != null && "true".equals(properties.getProperty("easyrec.firstrun"))) { properties.setProperty("easyrec.firstrun", "false"); File of = new File(overrideFolder.getFile(), "easyrec.database.properties"); properties.store(new FileOutputStream(of), ""); logger.info("First run after install... installing/updating default plugins!"); HashMap<URI, Version> installedPlugins = new HashMap<URI, Version>(); for (PluginVO plugin : pluginDAO.loadPluginInfos()) { installedPlugins.put(plugin.getPluginId().getUri(), plugin.getPluginId().getVersion()); }//from ww w .j a v a2 s . c om File[] files = new File[0]; if (pluginFolder.exists()) files = pluginFolder.getFile().listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); for (File file : files) { byte[] pluginContent = IOUtils.toByteArray(new FileInputStream(file)); PluginVO defaultPlugin = checkPlugin(pluginContent); if (defaultPlugin != null) { // if an older version of a default plugin exists, delete it if (installedPlugins.containsKey(defaultPlugin.getPluginId().getUri())) { if (installedPlugins.get(defaultPlugin.getPluginId().getUri()) .compareTo(defaultPlugin.getPluginId().getVersion()) < 0) { pluginDAO.deletePlugin(defaultPlugin.getPluginId().getUri(), installedPlugins.get(defaultPlugin.getPluginId().getUri())); } installedPlugins.remove(defaultPlugin.getPluginId().getUri()); } pluginDAO.storePlugin(defaultPlugin); installPlugin(defaultPlugin.getPluginId().getUri(), defaultPlugin.getPluginId().getVersion()); } } // set remaining installed plugins to status INSTALLED; need to be initialized manually after update for (Entry<URI, Version> plugin : installedPlugins.entrySet()) { pluginDAO.updatePluginState(plugin.getKey(), plugin.getValue(), LifecyclePhase.INSTALLED.toString()); } } // check if assocType "IS_RELATED" exists for all tenants, if not add it List<TenantVO> tenants = tenantService.getAllTenants(); for (TenantVO tenantVO : tenants) { tenantService.insertAssocTypeForTenant(tenantVO.getId(), AssocTypeDAO.ASSOCTYPE_IS_RELATED, true); } }
From source file:com.evolveum.midpoint.common.policy.ValuePolicyGenerator.java
/** * Count cardinality//from ww w. j a va 2 s. c om */ private static HashMap<Integer, ArrayList<String>> cardinalityCounter( HashMap<StringLimitType, ArrayList<String>> lims, ArrayList<String> password, Boolean skipMatchedLims, boolean uniquenessReached, OperationResult op) { HashMap<String, Integer> counter = new HashMap<String, Integer>(); for (StringLimitType l : lims.keySet()) { int counterKey = 1; ArrayList<String> chars = lims.get(l); int i = 0; if (null != password) { i = charIntersectionCounter(lims.get(l), password); } // If max is exceed then error unable to continue if (l.getMaxOccurs() != null && i > l.getMaxOccurs()) { OperationResult o = new OperationResult("Limitation check :" + l.getDescription()); o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + l.getMaxOccurs()); op.addSubresult(o); return null; // if max is all ready reached or skip enabled for minimal skip // counting } else if (l.getMaxOccurs() != null && i == l.getMaxOccurs()) { continue; // other cases minimum is not reached } else if ((l.getMinOccurs() == null || i >= l.getMinOccurs()) && !skipMatchedLims) { continue; } for (String s : chars) { if (null == password || !password.contains(s) || uniquenessReached) { // if (null == counter.get(s)) { counter.put(s, counterKey); // } else { // counter.put(s, counter.get(s) + 1); // } } } counterKey++; } // If need to remove disabled chars (already reached limitations) if (null != password) { for (StringLimitType l : lims.keySet()) { int i = charIntersectionCounter(lims.get(l), password); if (l.getMaxOccurs() != null && i > l.getMaxOccurs()) { OperationResult o = new OperationResult("Limitation check :" + l.getDescription()); o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + l.getMaxOccurs()); op.addSubresult(o); return null; } else if (l.getMaxOccurs() != null && i == l.getMaxOccurs()) { // limitation matched remove all used chars LOGGER.trace("Skip " + l.getDescription()); for (String charToRemove : lims.get(l)) { counter.remove(charToRemove); } } } } // Transpone to better format HashMap<Integer, ArrayList<String>> ret = new HashMap<Integer, ArrayList<String>>(); for (String s : counter.keySet()) { // if not there initialize if (null == ret.get(counter.get(s))) { ret.put(counter.get(s), new ArrayList<String>()); } ret.get(counter.get(s)).add(s); } return ret; }
From source file:org.broadleafcommerce.core.order.service.legacy.LegacyOrderServiceImpl.java
protected boolean bundleItemMatches(BundleOrderItem item1, BundleOrderItem item2) { if (item1.getSku() != null && item2.getSku() != null) { return item1.getSku().getId().equals(item2.getSku().getId()); }//from w ww. j a v a 2 s . c o m // Otherwise, scan the items. HashMap<Long, Integer> skuMap = new HashMap<Long, Integer>(); for (DiscreteOrderItem item : item1.getDiscreteOrderItems()) { if (skuMap.get(item.getSku().getId()) == null) { skuMap.put(item.getSku().getId(), Integer.valueOf(item.getQuantity())); } else { Integer qty = skuMap.get(item.getSku().getId()); skuMap.put(item.getSku().getId(), Integer.valueOf(qty + item.getQuantity())); } } // Now consume the quantities in the map for (DiscreteOrderItem item : item2.getDiscreteOrderItems()) { if (skuMap.containsKey(item.getSku().getId())) { Integer qty = skuMap.get(item.getSku().getId()); Integer newQty = Integer.valueOf(qty - item.getQuantity()); if (newQty.intValue() == 0) { skuMap.remove(item.getSku().getId()); } else if (newQty.intValue() > 0) { skuMap.put(item.getSku().getId(), newQty); } else { return false; } } else { return false; } } return skuMap.isEmpty(); }
From source file:org.broadinstitute.sting.utils.variant.GATKVariantContextUtils.java
public static Map<VariantContext.Type, List<VariantContext>> separateVariantContextsByType( Collection<VariantContext> VCs) { HashMap<VariantContext.Type, List<VariantContext>> mappedVCs = new HashMap<VariantContext.Type, List<VariantContext>>(); for (VariantContext vc : VCs) { // look at previous variant contexts of different type. If: // a) otherVC has alleles which are subset of vc, remove otherVC from its list and add otherVC to vc's list // b) vc has alleles which are subset of otherVC. Then, add vc to otherVC's type list (rather, do nothing since vc will be added automatically to its list) // c) neither: do nothing, just add vc to its own list boolean addtoOwnList = true; for (VariantContext.Type type : VariantContext.Type.values()) { if (type.equals(vc.getType())) continue; if (!mappedVCs.containsKey(type)) continue; List<VariantContext> vcList = mappedVCs.get(type); for (int k = 0; k < vcList.size(); k++) { VariantContext otherVC = vcList.get(k); if (allelesAreSubset(otherVC, vc)) { // otherVC has a type different than vc and its alleles are a subset of vc: remove otherVC from its list and add it to vc's type list vcList.remove(k);/*from www . jav a 2 s.co m*/ // avoid having empty lists if (vcList.size() == 0) mappedVCs.remove(type); if (!mappedVCs.containsKey(vc.getType())) mappedVCs.put(vc.getType(), new ArrayList<VariantContext>()); mappedVCs.get(vc.getType()).add(otherVC); break; } else if (allelesAreSubset(vc, otherVC)) { // vc has a type different than otherVC and its alleles are a subset of VC: add vc to otherVC's type list and don't add to its own mappedVCs.get(type).add(vc); addtoOwnList = false; break; } } } if (addtoOwnList) { if (!mappedVCs.containsKey(vc.getType())) mappedVCs.put(vc.getType(), new ArrayList<VariantContext>()); mappedVCs.get(vc.getType()).add(vc); } } return mappedVCs; }
From source file:com.ibm.bi.dml.hops.cost.CostEstimator.java
/** * /*from ww w .java 2 s . c o m*/ * @param inst * @param stats */ private void maintainCPInstVariableStatistics(CPInstruction inst, HashMap<String, VarStats> stats) { if (inst instanceof VariableCPInstruction) { String optype = inst.getOpcode(); String[] parts = InstructionUtils.getInstructionParts(inst.toString()); if (optype.equals("createvar")) { if (parts.length < 10) return; String varname = parts[1]; long rlen = Long.parseLong(parts[5]); long clen = Long.parseLong(parts[6]); long brlen = Long.parseLong(parts[7]); long bclen = Long.parseLong(parts[8]); long nnz = Long.parseLong(parts[9]); VarStats vs = new VarStats(rlen, clen, brlen, bclen, nnz, false); stats.put(varname, vs); //System.out.println(varname+" "+vs); } else if (optype.equals("cpvar")) { String varname = parts[1]; String varname2 = parts[2]; VarStats vs = stats.get(varname); stats.put(varname2, vs); } else if (optype.equals("mvvar")) { String varname = parts[1]; String varname2 = parts[2]; VarStats vs = stats.remove(varname); stats.put(varname2, vs); } else if (optype.equals("rmvar")) { String varname = parts[1]; stats.remove(varname); } } else if (inst instanceof DataGenCPInstruction) { DataGenCPInstruction randInst = (DataGenCPInstruction) inst; String varname = randInst.output.getName(); long rlen = randInst.getRows(); long clen = randInst.getCols(); long brlen = randInst.getRowsInBlock(); long bclen = randInst.getColsInBlock(); long nnz = (long) (randInst.getSparsity() * rlen * clen); VarStats vs = new VarStats(rlen, clen, brlen, bclen, nnz, true); stats.put(varname, vs); } else if (inst instanceof StringInitCPInstruction) { StringInitCPInstruction iinst = (StringInitCPInstruction) inst; String varname = iinst.output.getName(); long rlen = iinst.getRows(); long clen = iinst.getCols(); VarStats vs = new VarStats(rlen, clen, DMLTranslator.DMLBlockSize, DMLTranslator.DMLBlockSize, rlen * clen, true); stats.put(varname, vs); } else if (inst instanceof FunctionCallCPInstruction) { FunctionCallCPInstruction finst = (FunctionCallCPInstruction) inst; ArrayList<String> outVars = finst.getBoundOutputParamNames(); for (String varname : outVars) { stats.put(varname, _unknownStats); //System.out.println(varname+" "+vs); } } }