List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:org.xchain.namespaces.jsl.BaseTestSaxEvents.java
public void assertStartPrefixMappings(Iterator<SaxEventRecorder.SaxEvent> eventIterator, Map<String, String> prefixMappings, boolean allowOthers) throws Exception { // make sure that the event is there and of the proper type. assertTrue("There is not a start prefix event.", eventIterator.hasNext()); SaxEventRecorder.SaxEvent event = eventIterator.next(); assertEquals("There was not a start prefix mappings event.", SaxEventRecorder.EventType.START_PREFIX_MAPPING, event.getType()); HashMap<String, String> eventMapping = new HashMap<String, String>(); eventMapping.putAll(event.getPrefixMapping()); for (Map.Entry<String, String> entry : prefixMappings.entrySet()) { String definedNamespace = eventMapping.remove(entry.getKey()); assertEquals("The namespace for prefix " + entry.getKey() + " has the wrong definition.", entry.getValue(), definedNamespace); }/*from w ww. j av a 2 s. c o m*/ if (!allowOthers && !eventMapping.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("Extra prefixes found on element:"); for (Map.Entry<String, String> entry : eventMapping.entrySet()) { sb.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); } fail(sb.toString()); } }
From source file:at.pcgamingfreaks.Bukkit.RegisterablePluginCommand.java
/** * Un-Register command from Bukkit. Command will no longer get executed. *///from w ww. j a v a2s . c o m public void unregisterCommand() { try { Field result = owningPlugin.getServer().getPluginManager().getClass().getDeclaredField("commandMap"); result.setAccessible(true); @SuppressWarnings("unchecked") HashMap<String, Command> knownCommands = (HashMap<String, Command>) FIELD_KNOWN_COMMANDS .get(result.get(owningPlugin.getServer().getPluginManager())); knownCommands.remove(getName()); for (String alias : getAliases()) { if (knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(getName())) { knownCommands.remove(alias); } } } catch (Exception e) { owningPlugin.getLogger().warning("Failed unregistering command!"); e.printStackTrace(); } }
From source file:gov.nih.nci.cabig.caaers.service.synchronizer.StudyAgentsSynchronizer.java
public void migrate(Study dbStudy, Study xmlStudy, DomainObjectImportOutcome<Study> outcome) { //Ignore if the section is empty- Update- This is no longer true since CTEP sync should remove and override the agents // if(CollectionUtils.isEmpty(xmlStudy.getStudyAgents())){ // return; // }/*from w ww.ja v a2 s . com*/ //create an index of existing agents in the dbStudy. HashMap<String, StudyAgent> dbStudyAgentIndexMap = new HashMap<String, StudyAgent>(); for (StudyAgent sa : dbStudy.getActiveStudyAgents()) { dbStudyAgentIndexMap.put(sa.getAgentName(), sa); } //identify new study agents, also update existing ones. for (StudyAgent xmlStudyAgent : xmlStudy.getStudyAgents()) { StudyAgent sa = dbStudyAgentIndexMap.remove(xmlStudyAgent.getAgentName()); if (sa == null) { //newly added one, so add it to study dbStudy.addStudyAgent(xmlStudyAgent); continue; } //existing one - so update if necessary //BJ : the original code did not do anything, so nothing to update. //Update the StudyAgents as it can change between Adders Sync sa.setIndType(xmlStudyAgent.getIndType()); sa.setPartOfLeadIND(xmlStudyAgent.getPartOfLeadIND()); sa.getStudyAgentINDAssociations().clear(); for (StudyAgentINDAssociation ass : xmlStudyAgent.getStudyAgentINDAssociations()) { sa.addStudyAgentINDAssociation(ass); } } //now soft delete, all the ones not present in XML Study AbstractMutableRetireableDomainObject.retire(dbStudyAgentIndexMap.values()); }
From source file:gov.nih.nci.cabig.caaers.service.synchronizer.StudyInterventionSynchronizer.java
public void migrate(Study dest, Study src, DomainObjectImportOutcome<Study> studyDomainObjectImportOutcome) { HashMap<String, OtherIntervention> map = new HashMap<String, OtherIntervention>(); for (OtherIntervention otherIntervention : dest.getActiveOtherInterventions()) { map.put(otherIntervention.getHashKey(), otherIntervention); }// w w w . j a v a 2s .co m for (OtherIntervention xmlOtherIntervention : src.getOtherInterventions()) { OtherIntervention otherIntervention = map.remove(xmlOtherIntervention.getHashKey()); if (otherIntervention == null) { //newly added one, so add it to study dest.addOtherIntervention(xmlOtherIntervention); continue; } //Update- do nothing } //now soft delete, all the ones not present in XML Study AbstractMutableRetireableDomainObject.retire(map.values()); // List<OtherIntervention> otherInterventions = src.getOtherInterventions(); // if (CollectionUtils.isEmpty(otherInterventions)) return; // Set<String> destInterventionsSet = new HashSet<String>(); // // for (OtherIntervention otherIntervention : dest.getOtherInterventions()) { // destInterventionsSet.add(otherIntervention.getHashKey()); // } // // for (OtherIntervention otherIntervention : otherInterventions) { // if (destInterventionsSet.add(otherIntervention.getHashKey())) { // dest.addOtherIntervention(otherIntervention); // } // } }
From source file:org.duracloud.retrieval.config.RetrievalToolConfigParserTest.java
public void testStandardOptions(RetrievalToolConfigParser retConfigParser, String expectedPassword) throws Exception { HashMap<String, String> argsMap = getArgsMap(); // Process configs, make sure values match RetrievalToolConfig retConfig = retConfigParser.processOptions(mapToArray(argsMap)); checkStandardOptions(argsMap, retConfig); // Remove optional params argsMap.remove("-r"); argsMap.remove("-i"); argsMap.remove("-a"); argsMap.remove("-o"); argsMap.remove("-t"); argsMap.remove("-d"); argsMap.remove("-l"); argsMap.remove("-w"); // Process configs, make sure optional params are set to defaults retConfig = retConfigParser.processOptions(mapToArray(argsMap)); assertEquals(RetrievalToolConfigParser.DEFAULT_PORT, retConfig.getPort()); assertEquals(RetrievalToolConfigParser.DEFAULT_NUM_THREADS, retConfig.getNumThreads()); assertEquals(false, retConfig.isAllSpaces()); assertEquals(false, retConfig.isOverwrite()); assertEquals(true, retConfig.isApplyTimestamps()); assertEquals(false, retConfig.isListOnly()); assertEquals(expectedPassword, retConfig.getPassword()); assertNull(retConfig.getWorkDir());//from w w w . ja v a 2s .c om // Make sure error is thrown on missing required params for (String arg : argsMap.keySet()) { String failMsg = "An exception should have been thrown due to " + "missing arg: " + arg; removeArgFailTest(retConfigParser, argsMap, arg, failMsg); } // Make sure error is thrown when numerical args are not numerical String failMsg = "Port arg should require a numerical value"; addArgFailTest(retConfigParser, argsMap, "-r", "nonNum", failMsg); failMsg = "Threads arg should require a numerical value"; addArgFailTest(retConfigParser, argsMap, "-t", "nonNum", failMsg); }
From source file:org.jlibrary.cache.SimpleLocalCache.java
/** * @see org.jlibrary.client.cache.LocalCache#removeNodeFromCache(org.jlibrary.core.entities.Node) *///from ww w . j av a 2 s .c o m public void removeNodeFromCache(Node node) throws LocalCacheException { if (!isNodeCached(node)) { return; } String path = getNodePath(node); File file = new File(path); HashMap nodes = (HashMap) repositories.get(node.getRepository()); if (nodes != null) { nodes.remove(node.getId()); } try { FileUtils.forceDelete(file); } catch (IOException ioe) { throw new LocalCacheException("The node can't be removed from local cache"); } }
From source file:org.oscarehr.common.service.myoscar.ImmunizationsManager.java
public static Document toXml(Prevention prevention, HashMap<String, String> preventionExt) throws ParserConfigurationException { Document doc = XmlUtils.newDocument("Immunization"); String temp = StringUtils.trimToNull(prevention.getPreventionType()); XmlUtils.appendChildToRootIgnoreNull(doc, "Type", temp); if (prevention.getNextDate() != null) { temp = DateFormatUtils.ISO_DATETIME_FORMAT.format(prevention.getNextDate()); XmlUtils.appendChildToRootIgnoreNull(doc, "NextDate", temp); }// w ww.java 2 s. c om if (prevention.isRefused()) XmlUtils.appendChildToRootIgnoreNull(doc, "Status", "Refused"); else if (prevention.isIneligible()) XmlUtils.appendChildToRootIgnoreNull(doc, "Status", "Ineligible"); else XmlUtils.appendChildToRootIgnoreNull(doc, "Status", "Completed"); if (preventionExtLabels == null) { fillPreventionExtLabels(); } //append dose1 & dose2 to comments String comments = preventionExt.get("comments"); comments = appendLine(comments, "Dose1: ", preventionExt.get("dose1")); comments = appendLine(comments, "Dose2: ", preventionExt.get("dose2")); if (preventionExt.containsKey("comments")) preventionExt.remove("comments"); if (StringUtils.isNotBlank(comments)) preventionExt.put("comments", comments); //append prevention extra info to xml for (String key : preventionExtLabels.keySet()) { temp = StringUtils.trimToNull(preventionExt.get(key)); XmlUtils.appendChildToRootIgnoreNull(doc, preventionExtLabels.get(key), temp); } return (doc); }
From source file:org.dcm4chex.archive.hsm.VerifyTar.java
public static Map<String, byte[]> verify(InputStream in, String tarname, byte[] buf, ArrayList<String> objectNames) throws IOException, VerifyTarException { TarInputStream tar = new TarInputStream(in); try {//from w w w . j a v a 2 s . co m log.debug("Verify tar file: {}", tarname); TarEntry entry = tar.getNextEntry(); if (entry == null) throw new VerifyTarException("No entries in " + tarname); String entryName = entry.getName(); if (!"MD5SUM".equals(entryName)) throw new VerifyTarException("Missing MD5SUM entry in " + tarname); BufferedReader dis = new BufferedReader(new InputStreamReader(tar)); HashMap<String, byte[]> md5sums = new HashMap<String, byte[]>(); String line; while ((line = dis.readLine()) != null) { char[] c = line.toCharArray(); byte[] md5sum = new byte[16]; for (int i = 0, j = 0; i < md5sum.length; i++, j++, j++) { md5sum[i] = (byte) ((fromHexDigit(c[j]) << 4) | fromHexDigit(c[j + 1])); } md5sums.put(line.substring(34), md5sum); } Map<String, byte[]> entries = new HashMap<String, byte[]>(md5sums.size()); entries.putAll(md5sums); MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } while ((entry = tar.getNextEntry()) != null) { entryName = entry.getName(); log.debug("START: Check MD5 of entry: {}", entryName); if (objectNames != null && !objectNames.remove(entryName)) throw new VerifyTarException( "TAR " + tarname + " contains entry: " + entryName + " not in file list"); byte[] md5sum = (byte[]) md5sums.remove(entryName); if (md5sum == null) throw new VerifyTarException("Unexpected TAR entry: " + entryName + " in " + tarname); digest.reset(); in = new DigestInputStream(tar, digest); while (in.read(buf) > 0) ; if (!Arrays.equals(digest.digest(), md5sum)) { throw new VerifyTarException("Failed MD5 check of TAR entry: " + entryName + " in " + tarname); } log.debug("DONE: Check MD5 of entry: {}", entryName); } if (!md5sums.isEmpty()) throw new VerifyTarException("Missing TAR entries: " + md5sums.keySet() + " in " + tarname); if (objectNames != null && !objectNames.isEmpty()) throw new VerifyTarException( "Missing TAR entries from object list: " + objectNames.toString() + " in " + tarname); return entries; } finally { tar.close(); } }
From source file:nz.co.fortytwo.freeboard.server.AISProcessor.java
public HashMap<String, Object> handle(HashMap<String, Object> map) { String bodyStr = (String) map.get(Constants.AIS); if (logger.isDebugEnabled()) logger.debug("Processing AIS:" + bodyStr); if (StringUtils.isNotBlank(bodyStr)) { try {//w w w .j a v a 2s. com // dont need the AIS VDM now map.remove(Constants.AIS); AisPacket packet = handleLine(bodyStr); if (packet != null && packet.isValidMessage()) { //process message here AisMessage message = packet.getAisMessage(); if (logger.isDebugEnabled()) logger.debug("AisMessage:" + message.getClass() + ":" + message.toString()); //1,2,3 if (message instanceof AisPositionMessage) { AisVesselInfo vInfo = new AisVesselInfo((AisPositionMessage) message); map.put("AIS", vInfo); } //5,19,24 if (message instanceof AisStaticCommon) { AisVesselInfo vInfo = new AisVesselInfo((AisStaticCommon) message); map.put("AIS", vInfo); } if (message instanceof AisMessage18) { AisVesselInfo vInfo = new AisVesselInfo((AisMessage18) message); map.put("AIS", vInfo); } } //fireSentenceEvent(map, sentence); } catch (Exception e) { if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e); logger.error(e.getMessage() + " : " + bodyStr); } } return map; //https://github.com/dma-ais/AisLib /* * HD-SF. Free raw AIS data feed for non-commercial use. * hd-sf.com:9009 */ }
From source file:com.esri.geoevent.processor.serviceareacalculator.ServiceAreaCalculator.java
private String removeZFromGeom(String geomString) { geomString = new String(geomString); JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); JsonParser parser;//from www . ja v a2 s . c o m try { parser = factory.createJsonParser(geomString.getBytes()); TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { }; HashMap<String, Object> o = mapper.readValue(parser, typeRef); if (o.containsKey("z")) { o.remove("z"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mapper.writeValue(baos, o); geomString = baos.toString(); } } catch (Exception e) { throw new RuntimeException(LOGGER.translate("SERVICE_AREA_ERROR_REMOVING_Z", e.getMessage()), e); } return geomString; }