List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:org.apache.sysml.hops.ipa.InterProceduralAnalysis.java
private void removeConstantBinaryOps(DMLProgram dmlp) throws HopsException { //approach: scan over top-level program (guaranteed to be unconditional), //collect ones=matrix(1,...); remove b(*)ones if not outer operation HashMap<String, Hop> mOnes = new HashMap<String, Hop>(); for (StatementBlock sb : dmlp.getStatementBlocks()) { //pruning updated variables for (String var : sb.variablesUpdated().getVariableNames()) if (mOnes.containsKey(var)) mOnes.remove(var); //replace constant binary ops if (!mOnes.isEmpty()) rRemoveConstantBinaryOp(sb, mOnes); //collect matrices of ones from last-level statement blocks if (!(sb instanceof IfStatementBlock || sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock)) { collectMatrixOfOnes(sb.get_hops(), mOnes); }//from w w w . j a v a 2s. c om } }
From source file:org.kuali.student.r1.core.personsearch.service.impl.PersonSearch.java
public Map<String, String> convertPersonPropertiesToEntityProperties(Map<String, String> criteria) { LOG.debug("convertPersonPropertiesToEntityProperties: {}", criteria); 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); //Code Changed for JIRA-8997 - SONAR Critical issues - Performance - Inefficient use of keySet iterator instead of entrySet iterator if (criteria != null) { for (Map.Entry<String, String> entry : criteria.entrySet()) { //check active radio button String key = entry.getKey(); if (key.equals(KIMPropertyConstants.Person.ACTIVE)) { newCriteria.put(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); }// ww w .j a v a2 s . co m } // if no value was passed, skip the entry in the Map if (StringUtils.isEmpty(entry.getValue())) { 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 { criteria.put(key, CoreApiServiceLocator.getEncryptionService() .encrypt(criteria.get(key))); } catch (GeneralSecurityException ex) { LOG.error(String.format( "Unable to encrypt value for external ID search of type %s", 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"); } } LOG.debug("Converted: {}", newCriteria); return newCriteria; }
From source file:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java
/** * Substitutes in the values in params for templated values. After this method * is called, any subsequent calls to this method for the same object result in * an {@link IllegalStateException}. To preprocess the template again, * create another {@code ConfigurationTemplatePreprocessor} from the source XML. * * @param params a map from key to value of all the template parameters * @return the document as an XML string with the template parameters filled * in// w w w .ja va2 s . c o m * @throws MissingTemplateParameterException if any required parameter is * omitted * @throws IllegalStateException if this method has previously been called * on this object */ public String preprocess(Map<String, String> params) { HashMap<String, String> paramsCopy = new HashMap<String, String>(params); if (preprocessCalled) { throw new IllegalStateException("Preprocess can't be called twice for the same object"); } preprocessCalled = true; for (Entry<String, Element> entry : nameToValueElement.entrySet()) { Element valueElem = entry.getValue(); boolean isTemplateValue = valueElem.hasAttribute("template"); if (paramsCopy.containsKey(entry.getKey()) && isTemplateValue) { // Modifies the map in place, but that's fine for our use. Text valueData = (Text) valueElem.getFirstChild(); String newValue = paramsCopy.get(entry.getKey()); if (valueData != null) { valueData.setData(newValue); } else { valueElem.appendChild(doc.createTextNode(newValue)); } // Remove parameter, so we can tell if they gave us extras. paramsCopy.remove(entry.getKey()); } else if (isTemplateValue) { String templateAttribute = valueElem.getAttribute("template"); if ("required".equals(templateAttribute)) { throw new MissingTemplateParameterException( "Couldn't find expected parameter " + entry.getKey()); } else if ("optional".equals(templateAttribute)) { // The default value is the one already in the value text, so // leave it be. The one exception is if they self-closed the value tag, // so go ahead and add a Text child so Configuration doesn't barf. if (valueElem.getFirstChild() == null) { valueElem.appendChild(doc.createTextNode("")); } } else { throw new IllegalArgumentException("Value " + templateAttribute + " is not a valid template " + "attribute. Valid possibilities are: \"required\" or \"optional\"."); } // Remove parameter, so we can tell if they gave us extras. paramsCopy.remove(entry.getKey()); } else { throw new IllegalArgumentException( "Configuration property " + entry.getKey() + " is not a template property"); } // removeAttribute has no effect if the attributes don't exist valueElem.removeAttribute("template"); } if (paramsCopy.size() > 0) { // TODO(user): Is there a good way to bubble up all bad parameters? throw new UnexpectedTemplateParameterException("Parameter " + paramsCopy.keySet().iterator().next() + " wasn't found in the configuration template."); } return getDocAsXmlString(); }
From source file:com.surevine.alfresco.user.AlfrescoUserManagerTest.java
/** * Test the/*from w ww. j av a 2s. c om*/ * {@link AlfrescoUserManager#setUserDashboard(String, com.surevine.alfresco.dashboard.DashboardDefinition)} * method with a successful call * * @throws JSONException * @throws AlfrescoException */ @Test public void testSetUserDashboardSuccess() throws AlfrescoException, JSONException { final String testTemplateId = "test_template_id"; final String testUsername = "test_username"; // Construct a mocked dashboard definition DashboardDefinition dashboardDef = Mockito.mock(DashboardDefinition.class); int[] rowCounts = { 2, 0, 4 }; Map<String, List<String>> dashlets = DashboardDefinitionTest.createTestDashlets(rowCounts); when(dashboardDef.getDashlets()).thenReturn(dashlets); when(dashboardDef.getTemplateId()).thenReturn(testTemplateId); JSONObject successJSON = new JSONObject(); successJSON.put("success", true); when(alfrescoConnector.doSharePost(eq(SET_USER_DASHBOARD_SERVICE), Matchers.any(JSONObject.class))) .thenReturn(successJSON); // This will capture the parameters sent to the http service ArgumentCaptor<JSONObject> jsonCaptor = ArgumentCaptor.forClass(JSONObject.class); // Do that actual test call alfrescoUserManager.setUserDashboard(testUsername, dashboardDef); // Verify various stuff verify(dashboardDef).getDashlets(); verify(alfrescoConnector).doSharePost(eq(SET_USER_DASHBOARD_SERVICE), jsonCaptor.capture()); JSONObject jsonResult = jsonCaptor.getValue(); assertEquals("Template ID is wrong", testTemplateId, jsonResult.getString("templateId")); assertEquals("dashboardPage", "user/" + testUsername + "/dashboard", jsonResult.getString("dashboardPage")); JSONArray resultDashlets = jsonResult.getJSONArray("dashlets"); // This will be a map of all the expected dashlet urls which should be in the post HashMap<String, String> expectedDashlets = new HashMap<String, String>(); for (Entry<String, List<String>> entry : dashlets.entrySet()) { int col = Integer.valueOf(entry.getKey()) + 1; for (int i = 0; i < entry.getValue().size(); ++i) { expectedDashlets.put("component-" + col + "-" + (i + 1), entry.getValue().get(i)); } } // We firstly check that all the resulting dashlets are contained in the original dashboard definition for (int i = 0; i < resultDashlets.length(); ++i) { JSONObject resultDashlet = resultDashlets.getJSONObject(i); String regionId = resultDashlet.getString("regionId"); String url = resultDashlet.getString("url"); assertTrue("Unexpected dashlet regionId: " + regionId, expectedDashlets.containsKey(regionId)); assertEquals("Wrong url for regionId: " + regionId, expectedDashlets.get(regionId), url); // We will remove it from the map, then at the end if there are any left over we know something has gone wrong! expectedDashlets.remove(regionId); } // If there are expected dashlets left then they were not all included in the post assertTrue("Dashlets were expected but not delivered", expectedDashlets.size() == 0); }
From source file:org.apache.hadoop.fs.azure.AzureNativeFileSystemStore.java
private static void removeMetadataAttribute(CloudBlobWrapper blob, String key) { HashMap<String, String> metadata = blob.getMetadata(); if (metadata != null) { metadata.remove(key); blob.setMetadata(metadata);// w w w .j a v a2 s.c om } }
From source file:org.gluu.oxtrust.ldap.cache.service.CacheRefreshTimer.java
private ArrayList<GluuInumMap> applyChangesToInumMap(HashMap<String, GluuInumMap> inumInumMap, HashMap<CacheCompoundKey, GluuInumMap> addedPrimaryKeyAttrValueInumMap, List<String> removedGluuInumMaps) { log.info("There are '{0}' entries before updating inum list", inumInumMap.size()); for (String removedGluuInumMap : removedGluuInumMaps) { inumInumMap.remove(removedGluuInumMap); }/* w w w. ja va 2 s . c o m*/ log.info("There are '{0}' entries after removal '{1}' entries", inumInumMap.size(), removedGluuInumMaps.size()); ArrayList<GluuInumMap> currentInumMaps = new ArrayList<GluuInumMap>(inumInumMap.values()); currentInumMaps.addAll(addedPrimaryKeyAttrValueInumMap.values()); log.info("There are '{0}' entries after adding '{1}' entries", currentInumMaps.size(), addedPrimaryKeyAttrValueInumMap.size()); return currentInumMaps; }
From source file:org.wso2.carbon.application.mgt.ApplicationAdmin.java
/** * Deletes an entire application by deleting all its artifacts * * @param faultyAppName - name of the Application to be deleted * @throws Exception - error on getting carbon app service */// w ww .j ava 2 s . c om public void deleteFaultyApplication(String[] faultyAppName) throws Exception { String tenantId = AppDeployerUtils.getTenantIdString(getAxisConfig()); HashMap<String, Exception> faultyCarbonAppList = AppManagementServiceComponent.getAppManager() .getFaultyCarbonApps(tenantId); for (String faultyCarbonApplication : faultyAppName) { // If appName is null throw an exception if (faultyCarbonApplication == null) { handleException("Application name can't be null"); return; } // CarbonApplication instance to delete String currentApp = null; String filename = null; // Iterate all applications for this tenant and find the application to delete for (String carbonApp : faultyCarbonAppList.keySet()) { filename = carbonApp.substring(carbonApp.lastIndexOf('/') + 1); if (faultyCarbonApplication.equals(filename) || faultyCarbonApplication.equals(filename.substring(0, filename.lastIndexOf('_')))) { currentApp = carbonApp; faultyCarbonAppList.remove(currentApp); break; } } // If requested application not found, throw an exception if (currentApp == null) { handleException("No Carbon Application found of the name : " + faultyCarbonApplication); return; } // Remove the app artifact file from repository, cApp hot undeployer will do the rest String appFilePath = currentApp; File file = new File(appFilePath); if (file.exists() && !file.delete()) { log.error("Artifact file couldn't be deleted for Application : " + filename); } } }
From source file:StorageEngineClient.CombineColumnStorageFileInputFormat.java
private void getMoreSplits(JobConf job, Path[] paths1, long maxSize, long minSizeNode, long minSizeRack, List<CombineFileSplit> splits) throws IOException { if (paths1.length == 0) { return;//from w ww . ja va 2s .c o m } HashMap<String, Path> strpath = new HashMap<String, Path>(); HashMap<String, Long> pathmap = new HashMap<String, Long>(); for (Path p : paths1) { if (p.toString().contains("_idx")) { String pstr = p.toString().substring(0, p.toString().lastIndexOf("_idx")); if (!pathmap.containsKey(pstr)) { pathmap.put(pstr, 0l); strpath.put(pstr, p); } long len = p.getFileSystem(job).getFileStatus(p).getLen(); pathmap.put(pstr, pathmap.get(pstr) + len); } } Path[] paths = new Path[pathmap.size()]; int ii = 0; for (String str : pathmap.keySet()) { paths[ii++] = strpath.get(str); } OneFileInfo[] files; HashMap<String, List<OneBlockInfo>> rackToBlocks = new HashMap<String, List<OneBlockInfo>>(); HashMap<OneBlockInfo, String[]> blockToNodes = new HashMap<OneBlockInfo, String[]>(); HashMap<String, List<OneBlockInfo>> nodeToBlocks = new HashMap<String, List<OneBlockInfo>>(); files = new OneFileInfo[paths.length]; long totLength = 0; ii = 0; for (String str : pathmap.keySet()) { files[ii] = new OneFileInfo(strpath.get(str), job, rackToBlocks, blockToNodes, nodeToBlocks); totLength += pathmap.get(str); } ArrayList<OneBlockInfo> validBlocks = new ArrayList<OneBlockInfo>(); ArrayList<String> nodes = new ArrayList<String>(); long curSplitSize = 0; for (Iterator<Map.Entry<String, List<OneBlockInfo>>> iter = nodeToBlocks.entrySet().iterator(); iter .hasNext();) { Map.Entry<String, List<OneBlockInfo>> one = iter.next(); nodes.add(one.getKey()); List<OneBlockInfo> blocksInNode = one.getValue(); for (OneBlockInfo oneblock : blocksInNode) { if (blockToNodes.containsKey(oneblock)) { validBlocks.add(oneblock); blockToNodes.remove(oneblock); curSplitSize += oneblock.length; if (maxSize != 0 && curSplitSize >= maxSize) { addCreatedSplit(job, splits, nodes, validBlocks); curSplitSize = 0; validBlocks.clear(); } } } if (minSizeNode != 0 && curSplitSize >= minSizeNode) { addCreatedSplit(job, splits, nodes, validBlocks); } else { for (OneBlockInfo oneblock : validBlocks) { blockToNodes.put(oneblock, oneblock.hosts); } } validBlocks.clear(); nodes.clear(); curSplitSize = 0; } ArrayList<OneBlockInfo> overflowBlocks = new ArrayList<OneBlockInfo>(); ArrayList<String> racks = new ArrayList<String>(); while (blockToNodes.size() > 0) { for (Iterator<Map.Entry<String, List<OneBlockInfo>>> iter = rackToBlocks.entrySet().iterator(); iter .hasNext();) { Map.Entry<String, List<OneBlockInfo>> one = iter.next(); List<OneBlockInfo> blocks = one.getValue(); boolean createdSplit = false; for (OneBlockInfo oneblock : blocks) { if (blockToNodes.containsKey(oneblock)) { validBlocks.add(oneblock); blockToNodes.remove(oneblock); curSplitSize += oneblock.length; for (int i = 0; i < oneblock.hosts.length; i++) { racks.add(oneblock.hosts[i]); } if (maxSize != 0 && curSplitSize >= maxSize) { addCreatedSplit(job, splits, racks, validBlocks); createdSplit = true; break; } } } if (createdSplit) { curSplitSize = 0; validBlocks.clear(); racks.clear(); continue; } if (!validBlocks.isEmpty()) { if (minSizeRack != 0 && curSplitSize >= minSizeRack) { addCreatedSplit(job, splits, racks, validBlocks); } else { overflowBlocks.addAll(validBlocks); } } curSplitSize = 0; validBlocks.clear(); racks.clear(); } } assert blockToNodes.isEmpty(); assert curSplitSize == 0; assert validBlocks.isEmpty(); assert racks.isEmpty(); for (OneBlockInfo oneblock : overflowBlocks) { validBlocks.add(oneblock); curSplitSize += oneblock.length; for (int i = 0; i < oneblock.racks.length; i++) { racks.add(oneblock.hosts[i]); } if (maxSize != 0 && curSplitSize >= maxSize) { addCreatedSplit(job, splits, racks, validBlocks); curSplitSize = 0; validBlocks.clear(); racks.clear(); } } if (!validBlocks.isEmpty()) { addCreatedSplit(job, splits, racks, validBlocks); } }
From source file:playground.pieter.events.MultiModalFlowAndDensityCollector.java
public HashMap<Id, double[]> calculateDensity(HashMap<Id, int[]> deltaFlow, Map<Id, ? extends Link> links) { // send actual link info.) HashMap<Id, double[]> density = new HashMap<>(); for (Id linkId : deltaFlow.keySet()) { density.put(linkId, null);//from w ww . jav a 2 s. c o m } for (Id linkId : density.keySet()) { int[] deltaflowBins = deltaFlow.get(linkId);// give labels to // deltaflowBins double[] densityBins = new double[deltaflowBins.length]; Link link = links.get(linkId); densityBins[0] = deltaflowBins[0]; for (int i = 1; i < deltaflowBins.length; i++) { densityBins[i] = (densityBins[i - 1] + deltaflowBins[i]); } for (int i = 1; i < deltaflowBins.length; i++) { densityBins[i] = densityBins[i] / (link.getLength() * link.getNumberOfLanes()) * 1000; } density.put(linkId, densityBins); deltaFlow.remove(linkId); } return density; }