List of usage examples for java.util HashMap get
public V get(Object key)
From source file:de.unileipzig.ub.indexer.App.java
public static String getContentIdentifier(String line, String identifier) throws IOException { final HashMap record = sharedMapper.readValue(line, HashMap.class); final HashMap content = (HashMap) record.get("content"); final String id = content.get(identifier).toString(); return id;/*from w ww . ja v a 2 s .co m*/ }
From source file:com.cssweb.quote.util.StockInfo.java
private static List<HashMap<String, String>> getStockListByType(int type, String exchange) { List<HashMap<String, String>> l = getStockListByType(type); List<HashMap<String, String>> t = new ArrayList<HashMap<String, String>>(); int tlen = l.size(); for (int i = 0; i < tlen; i++) { HashMap<String, String> h = l.get(i); if (exchange.equals(h.get("exchange"))) { h.put("exchange", h.get("exchange")); h.put("stockcode", h.get("stockcode")); h.put("stockname", h.get("stockname")); t.add(h);//from w ww. ja v a 2 s . c o m } } return t; }
From source file:com.morphoss.jumble.models.Word.java
/** * This method gets the word and its details like imagepath from the JSON * file/*from w ww.jav a 2 s . c o m*/ * * @param json * @param categories * @return * @throws JSONException */ public static HashMap<String, Word> getWordFromJson(JSONObject json, HashMap<Integer, Category> categories) throws JSONException { Log.d(TAG, "creating ArrayList"); HashMap<String, Word> words = new HashMap<String, Word>(); JSONArray keys = json.names(); for (int i = 0; i < keys.length(); i++) { String key = (String) keys.get(i); JSONObject data = json.getJSONObject(key); int catId = data.getInt("category"); Word newWord = new Word(key, data); categories.get(catId).addWord(newWord); words.put(key, newWord); } return words; }
From source file:org.grameenfoundation.consulteca.utils.HttpHelpers.java
private static void addHeaders(HttpGet httpGet, HashMap<String, String> headers) { if (headers == null) { return;//from www . ja va 2s .co m } Set<String> keys = headers.keySet(); for (String key : keys) { httpGet.addHeader(key, headers.get(key)); } }
From source file:org.grameenfoundation.consulteca.utils.HttpHelpers.java
private static void addHeaders(HttpPost httpPost, HashMap<String, String> headers) { if (headers == null) { return;//from w ww .j av a2 s .c o m } Set<String> keys = headers.keySet(); for (String key : keys) { httpPost.addHeader(key, headers.get(key)); } }
From source file:com.openkm.dao.HibernateUtil.java
/** * Load specific database import/*from ww w .j a va2s.co m*/ */ public static void executeSentences(final Reader rd) { Session session = null; Transaction tx = null; try { session = sessionFactory.openSession(); tx = session.beginTransaction(); session.doWork(new Work() { @Override public void execute(Connection con) throws SQLException { try { for (HashMap<String, String> error : LegacyDAO.executeScript(con, rd)) { log.error("Error during script execution at line {}: {} [ {} ]", new Object[] { error.get("ln"), error.get("msg"), error.get("sql") }); } } catch (IOException e) { log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(rd); } } }); commit(tx); } catch (Exception e) { rollback(tx); log.error(e.getMessage(), e); } }
From source file:com.vmware.qe.framework.datadriven.utils.XMLUtil.java
/** * Returns the text value of a node where a sibling tag name and value is known. * <p>//ww w . j a va 2 s .c o m * For example, in the XML snippet below, if you pass in "cat" as the parentTagName, "name" as * the childTagName, and "MrBiggles" as the childTagValue, and specify "color" as the * siblingTagName, the method would return "Grey". * <p> * Example XML: * * <pre> * <cat> * <name>MrBiggles</name> * <color>Grey</color> * </cat> * <cat> * <name>Boris</name> * <color>Black</color> * </cat> * </pre> * * @param xmlDocAsString The XML document as a String * @param parentTagName The tag name of the parent elements that should contain the sibling * nodes * @param childTagName The tag name of the known child element * @param childTagValue The known text value of the child element * @param siblingTagName The tag name of the sibling node * @return String The text value of the sibling node * @throws Exception */ public static String findSiblingNodeValue(String xmlDocAsString, String parentTagName, String childTagName, String childTagValue, String siblingTagName) throws Exception { String siblingNodeValue = null; Document xmlDoc = XMLUtil.getXmlDocumentElement(xmlDocAsString); NodeList parentNodes = xmlDoc.getElementsByTagName(parentTagName); if (parentNodes != null) { for (int i = 0; i < parentNodes.getLength(); i++) { Node parentNode = parentNodes.item(i); HashMap<String, Node> childNodes = XMLUtil.getChildrenByTagNames(parentNode); Node childNode = childNodes.get(childTagName); String tmpChildNodeVal = XMLUtil.getNodeTextValue(childNode); if (childTagValue.equals(tmpChildNodeVal)) { log.info("Found node: " + childTagName + " with value: " + childTagValue); Node siblingNode = childNodes.get(siblingTagName); if (siblingNode != null) { siblingNodeValue = XMLUtil.getNodeTextValue(siblingNode); log.info("Found the sibling node: " + siblingTagName + " = " + siblingNodeValue); break; } else { log.warn("No sibling node named: " + siblingTagName + " was found."); } } } } else { log.warn("There were no elements with tag name: " + parentTagName); } return siblingNodeValue; }
From source file:Main.java
@SuppressWarnings("unchecked") static public LinkedHashMap<Object, Comparable> sortHashMapByValues(HashMap<Object, Comparable> passedMap) { ArrayList mapKeys = new ArrayList(passedMap.keySet()); ArrayList mapValues = new ArrayList(passedMap.values()); Collections.sort(mapValues);/*from ww w .j a v a 2s.c om*/ Collections.sort(mapKeys); LinkedHashMap<Object, Comparable> sortedMap = new LinkedHashMap<Object, Comparable>(); Iterator<Comparable> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { Comparable val = valueIt.next(); Iterator keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { Object key = keyIt.next(); Comparable comp = passedMap.get(key); if (comp.equals(val)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put(key, val); break; } } } return sortedMap; }
From source file:fr.lissi.belilif.om2m.rest.WebServiceActions.java
/** * Do get.//w ww .j ava 2 s . c om * * @param uri * the uri * @param headers * the headers * @return the string * @throws ClientProtocolException * the client protocol exception * @throws IOException * Signals that an I/O exception has occurred. * @throws HttpResponseException * the http response exception */ public static HttpGetSimpleResp doGet(String uri, HashMap<String, String> headers) throws ClientProtocolException, IOException, HttpResponseException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGetSimpleResp resp = new HttpGetSimpleResp(); try { HttpGet httpGet = new HttpGet(uri); for (String key : headers.keySet()) { httpGet.addHeader(key, headers.get(key)); } CloseableHttpResponse response = httpclient.execute(httpGet); resp.setStatusCode(response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { try { HttpEntity entity = response.getEntity(); if (entity != null) { // TODO to use for performance in the future // ResponseHandler<String> handler = new BasicResponseHandler(); resp.setResult(new BasicResponseHandler().handleResponse(response)); } EntityUtils.consume(entity); } finally { response.close(); } } else { // TODO optimiz (repeating code) throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } finally { httpclient.close(); } return resp; }
From source file:de.unileipzig.ub.indexer.App.java
public static String extractSrcSHA1(String filename) throws IOException { // extract the meta.srcsha1 attribute from filename String srcSHA1 = null;// ww w . j a va 2 s. co m try { final FileReader fr = new FileReader(filename); final BufferedReader br = new BufferedReader(fr); String line; // one line is one document while ((line = br.readLine()) != null) { final ObjectMapper mapper = new ObjectMapper(); final HashMap record = mapper.readValue(line, HashMap.class); final HashMap meta = (HashMap) record.get("meta"); srcSHA1 = meta.get("srcsha1").toString(); break; } } catch (IOException ioe) { logger.error(filename + ": " + ioe); System.exit(1); } if (srcSHA1 == null) { logger.fatal(filename + ": meta.srcsha1 not found. Aborting."); throw new IOException("meta.srcsha1 not found. Aborting."); } return srcSHA1; }