List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:Main.java
public static Object removeAdditionalInstanceField(Object obj, String key) { if (obj == null) throw new NullPointerException("object must not be null"); if (key == null) throw new NullPointerException("key must not be null"); HashMap<String, Object> objectFields; synchronized (additionalFields) { objectFields = additionalFields.get(obj); if (objectFields == null) return null; }/* www.ja va2 s. c om*/ synchronized (objectFields) { return objectFields.remove(key); } }
From source file:de.hbz.lobid.helper.CompareJsonMaps.java
private static void handleUnorderedValues(final HashMap<String, String> actualMap, final Entry<String, String> e) { if (checkIfAllValuesAreContainedUnordered(actualMap.get(e.getKey()), e.getValue())) { actualMap.remove(e.getKey()); CompareJsonMaps.logger.debug("Removed " + e.getKey()); } else {//w ww .j a v a 2s. co m CompareJsonMaps.logger.debug("Missing/wrong: " + e.getKey() + ", will fail"); } }
From source file:com.dtolabs.rundeck.core.common.NodeEntryFactory.java
/** * Create NodeEntryImpl from map data. It will convert "tags" of type String as a comma separated list of tags, or * "tags" a collection of strings into a set. It will remove properties excluded from allowed import. * * @param map input map data/* ww w .j av a 2 s .c o m*/ * * @return * * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public static NodeEntryImpl createFromMap(final Map<String, Object> map) throws IllegalArgumentException { final NodeEntryImpl nodeEntry = new NodeEntryImpl(); final HashMap<String, Object> newmap = new HashMap<String, Object>(map); for (final String excludeProp : excludeProps) { newmap.remove(excludeProp); } if (null != newmap.get("tags") && newmap.get("tags") instanceof String) { String tags = (String) newmap.get("tags"); String[] data; if ("".equals(tags.trim())) { data = new String[0]; } else { data = tags.split(","); } final HashSet set = new HashSet(); for (final String s : data) { if (null != s && !"".equals(s.trim())) { set.add(s.trim()); } } newmap.put("tags", set); } else if (null != newmap.get("tags") && newmap.get("tags") instanceof Collection) { Collection tags = (Collection) newmap.get("tags"); HashSet data = new HashSet(); for (final Object tag : tags) { if (null != tag && !"".equals(tag.toString().trim())) { data.add(tag.toString().trim()); } } newmap.put("tags", data); } else if (null != newmap.get("tags")) { Object o = newmap.get("tags"); newmap.put("tags", new HashSet(Arrays.asList(o.toString().trim()))); } try { BeanUtils.populate(nodeEntry, newmap); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } if (null == nodeEntry.getNodename()) { throw new IllegalArgumentException("Required property 'nodename' was not specified"); } if (null == nodeEntry.getHostname()) { throw new IllegalArgumentException("Required property 'hostname' was not specified"); } if (null == nodeEntry.getAttributes()) { nodeEntry.setAttributes(new HashMap<String, String>()); } //populate attributes with any keys outside of nodeprops for (final Map.Entry<String, Object> entry : newmap.entrySet()) { if (!ResourceXMLConstants.allPropSet.contains(entry.getKey())) { nodeEntry.setAttribute(entry.getKey(), (String) entry.getValue()); } } return nodeEntry; }
From source file:org.nines.RdfDocumentParser.java
public static HashMap<String, HashMap<String, ArrayList<String>>> parse(final File file, ErrorReport errorReport, LinkCollector linkCollector, RDFIndexerConfig config) throws IOException { largestTextSize = 0;//w w w.ja v a 2 s . c o m RDFXMLParser parser = new RDFXMLParser(); NinesStatementHandler statementHandler = new NinesStatementHandler(errorReport, linkCollector, config); statementHandler.setFile(file); parser.setRDFHandler(statementHandler); parser.setParseErrorListener(new ParseListener(file, errorReport)); parser.setVerifyData(true); parser.setStopAtFirstError(false); // parse file try { String content = validateContent(file, errorReport); parser.parse(new StringReader(content), "http://foo/" + file.getName()); } catch (RDFParseException e) { errorReport.addError(new IndexerError(file.getName(), "", "Parse Error on Line " + e.getLineNumber() + ": " + e.getMessage())); } catch (RDFHandlerException e) { errorReport.addError( new IndexerError(file.getName(), "", "StatementHandler Exception: " + e.getMessage())); } catch (Exception e) { errorReport.addError(new IndexerError(file.getName(), "", "RDF Parser Error: " + e.getMessage())); e.printStackTrace(); } // retrieve parsed data HashMap<String, HashMap<String, ArrayList<String>>> docHash = statementHandler .getDocuments(config.isPagesArchive()); // process tags Collection<HashMap<String, ArrayList<String>>> documents = docHash.values(); for (HashMap<String, ArrayList<String>> document : documents) { // normalize tags, replace spaces with dashes, lowercase ArrayList<String> tags = document.remove("tag"); if (tags != null) { for (int i = 0; i < tags.size(); i++) { String tag = tags.get(i); tag = tag.toLowerCase(); tag = tag.replaceAll(" ", "-"); tags.set(i, tag); } // username is archive name String archive = document.get("archive").get(0); ArrayList<String> nameList = new ArrayList<String>(); nameList.add(archive); document.put("username", nameList); document.put(archive + "_tag", tags); } } largestTextSize = statementHandler.getLargestTextSize(); return docHash; }
From source file:org.shangridocs.services.omim.OmimResource.java
public static String createStandardJson(String Search_link, String Num_results, ArrayList<HashMap<String, String>> entries) { String json = ""; json += "{";/*from ww w.j a va2 s . c o m*/ json += "\"Num_results\":\"" + Num_results + "\","; json += "\"Search_link\":\"" + Search_link + "\","; json += "\"Response\":["; for (HashMap<String, String> map : entries) { json += "{"; json += "\"Title\":\"" + map.get("Title") + "\","; map.remove("Title"); json += "\"ID\":\"" + map.get("ID") + "\","; map.remove("ID"); json += "\"Description\":\"" + map.get("Description") + "\","; map.remove("Description"); json += "\"Detail_link\":\"" + map.get("Detail_link") + "\","; map.remove("Detail_link"); json += "\"Properties\":{"; for (String key : map.keySet()) { json += "\"" + key + "\":\"" + map.get(key) + "\","; } // remove the last comma if (String.valueOf(json.charAt(json.length() - 1)).equals(",")) json = json.substring(0, json.length() - 1); json += "}"; json += "},"; } // remove the last comma if (String.valueOf(json.charAt(json.length() - 1)).equals(",")) json = json.substring(0, json.length() - 1); json += "]"; json += "}"; return json.replace("\n", " "); }
From source file:org.squale.welcom.taglib.table.ListColumnSort.java
/** * supprimer l'ordre de trie pour la table * /*w ww .jav a2s . co m*/ * @param session : Session * @param name : nom bean de la table * @param property : nom de la property */ public static synchronized void resetKeySortOfTable(final HttpSession session, String name, String property) { HashMap tableKeySort = (HashMap) session.getAttribute(TABLE_TAG_KEY_SORT); String cle = getCle(name, property); if (tableKeySort != null && tableKeySort.containsKey(cle)) { tableKeySort.remove(cle); } }
From source file:org.lealone.cluster.db.ClusterMetaData.java
public static AbstractReplicationStrategy getReplicationStrategy(Database db) { if (db.getReplicationProperties() == null) return defaultReplicationStrategy; AbstractReplicationStrategy replicationStrategy = replicationStrategys.get(db); if (replicationStrategy == null) { HashMap<String, String> map = new HashMap<>(db.getReplicationProperties()); String className = map.remove("class"); if (className == null) { throw new ConfigurationException("Missing replication strategy class"); }//w w w . ja v a2s .c o m replicationStrategy = AbstractReplicationStrategy.createReplicationStrategy(db.getName(), AbstractReplicationStrategy.getClass(className), StorageService.instance.getTokenMetaData(), DatabaseDescriptor.getEndpointSnitch(), map); replicationStrategys.put(db, replicationStrategy); } return replicationStrategy; }
From source file:no.trank.openpipe.solr.step.SolrDocumentProcessor.java
private static Map<String, String> findDocAttributes(HashMap<String, List<String>> solrOutputDoc) { final List<String> boostList = solrOutputDoc.remove(BOOST_KEY); final Map<String, String> attribs; if (boostList != null && !boostList.isEmpty()) { if (boostList.size() > 1) { log.warn("Got multiple boost values {} for document", boostList); }/* w w w. j a v a2 s.c om*/ attribs = Collections.singletonMap(BOOST_KEY, boostList.get(0)); } else { attribs = Collections.emptyMap(); } return attribs; }
From source file:at.treedb.jslib.JsLib.java
/** * Unloads a <code>JsLib</code> object. * /*from w ww . ja v a 2 s . c o m*/ * @param name * name of the * @param version * @throws IOException */ public static void unloadLib(String name, String version) throws IOException { if (jsLibs == null) { return; } synchronized (lockObj) { HashMap<Version, JsLib> v = jsLibs.get(name); if (v != null) { JsLib lib = v.remove(new Version(version)); if (lib != null) { if (lib.inChannel != null) { lib.inChannel.close(); lib.dumpFile.delete(); } // free file cache for the GC lib.fileCache = null; if (v.isEmpty()) { jsLibs.remove(name); } } ArchiveClassLoader.clearCache(name, version); } } }
From source file:uk.ac.soton.itinnovation.ecc.service.utils.MetricCalculator.java
public static Map<String, Integer> countValueFrequencies(Set<Measurement> measurements) { HashMap<String, Integer> freqMap = new HashMap<>(); if (measurements != null && !measurements.isEmpty()) { for (Measurement m : measurements) { String value = m.getValue(); if (value != null) { if (freqMap.containsKey(value)) { int count = freqMap.remove(value); freqMap.put(value, ++count); } else freqMap.put(value, 1); }/*from w w w.ja v a 2 s. com*/ } } return freqMap; }