List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:eu.scape_project.hawarp.utils.StringUtils.java
public static String normaliseMimetype(String mime) { String normalised = getStrUntilChar(mime, ";"); HashMap<String, String> replMap = new HashMap<String, String>(); replMap.put("no-type", "application/octet-stream"); for (String key : replMap.keySet()) { if (normalised.contains(key)) { normalised = normalised.replace(key, replMap.get(key)); }/*from www . j ava 2 s .c om*/ } return normalised.toLowerCase(); }
From source file:Main.java
/** * Method getHashMapFromVector./*from ww w. j a v a 2s .com*/ * @param vector Vector * @return HashMap */ public static HashMap getHashMapFromVector(Vector vector) { HashMap hashMap = new HashMap(vector.size()); for (int i = 0; i < vector.size(); i++) { hashMap.put(vector.elementAt(i), vector.elementAt(i)); } return hashMap; }
From source file:Main.java
private static String getString(HashMap<String, String> stringTable, String string) { String result = stringTable.get(string); if (result == null) { stringTable.put(string, string); result = string;//from ww w . j av a 2 s. c o m } return result; }
From source file:Main.java
/** * @param entries the <i>final</i> set of entries to add to the newly created <i>unmodifiable</i> map * @return an <i>unmodifiable</i> map with all given entries *///from w w w .j a v a 2 s . c o m public static <K, V> Map<K, V> map(final Entry<K, V>... entries) { final HashMap<K, V> map = new HashMap<K, V>(entries.length); for (final Entry<K, V> entry : entries) { map.put(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(map); }
From source file:Main.java
public static Map<String, String> convertBeanToMap(Object bean) throws IllegalArgumentException, IllegalAccessException { Field[] fields = bean.getClass().getDeclaredFields(); HashMap<String, String> data = new HashMap<String, String>(); for (Field field : fields) { field.setAccessible(true);//from w w w. ja v a2s . c o m data.put(field.getName(), (String) field.get(bean)); } return data; }
From source file:Main.java
public static Map<String, Object> getMapValueSubset(Map<String, Object> list, String pattern) { HashMap<String, Object> result = new HashMap<>(); for (String key : list.keySet()) { if (key.matches(pattern)) { result.put(key, list.get(key)); }//from w w w .j av a 2s.c o m } return result; }
From source file:at.tugraz.ist.catroid.test.utils.XMLValidationUtil.java
public static void sendProjectXMLToServerForValidating(String fullPathFilename) throws IOException, JSONException { String xmlContent = readTextFile(fullPathFilename); HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put("xmlToValidate", xmlContent); ConnectionWrapper connection = new ConnectionWrapper(); String responce = connection.doHttpPost(XML_VALIDATING_URL, postValues); JSONObject jsonResponce = new JSONObject(responce); Log.i(LOG_TAG, "json responce: " + jsonResponce.toString()); boolean valid = jsonResponce.getBoolean("valid"); String message = jsonResponce.optString("message"); Assert.assertTrue(message, valid);//from w ww . j a v a 2 s.c o m }
From source file:Main.java
public static Map<String, List<String>> asMap(String key, String... args) { HashMap<String, List<String>> result = new HashMap<String, List<String>>(); if (args != null) { result.put(key, Arrays.asList(args)); }/*from w w w .j a v a2s .c om*/ return result; }
From source file:Main.java
public static List<Map<String, String>> ReadPlaylistItemsFromFile(String path, String filename) { List<Map<String, String>> results = new ArrayList<Map<String, String>>(); try {//from w ww .j av a2 s . com File fXmlFile = new File(path, filename); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList songList = doc.getElementsByTagName("song"); Log.d("ReadItemsFromFile", "List Length: " + songList.getLength()); for (int i = 0; i < songList.getLength(); i++) { Node nNode = songList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; HashMap<String, String> mapElement = new HashMap<String, String>(); mapElement.put("name", eElement.getElementsByTagName("name").item(0).getTextContent()); mapElement.put("artist", eElement.getElementsByTagName("artist").item(0).getTextContent()); mapElement.put("startTime", eElement.getElementsByTagName("startTime").item(0).getTextContent()); mapElement.put("url", eElement.getElementsByTagName("url").item(0).getTextContent()); results.add(mapElement); } } } catch (Exception e) { e.printStackTrace(); return null; } return results; }
From source file:com.kstenschke.shifter.models.shiftertypes.CssUnit.java
/** * @param stylesheet/*from www . j ava 2 s .c om*/ * @return most prominently used unit of given stylesheet, 'px' if none used yet */ public static String determineMostProminentUnit(String stylesheet) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put(UNIT_CM, StringUtils.countMatches(stylesheet, UNIT_CM + ";")); map.put(UNIT_EM, StringUtils.countMatches(stylesheet, UNIT_EM + ";")); map.put(UNIT_IN, StringUtils.countMatches(stylesheet, UNIT_IN + ";")); map.put(UNIT_MM, StringUtils.countMatches(stylesheet, UNIT_MM + ";")); map.put(UNIT_PC, StringUtils.countMatches(stylesheet, UNIT_PC + ";")); map.put(UNIT_PT, StringUtils.countMatches(stylesheet, UNIT_PT + ";")); map.put(UNIT_PX, StringUtils.countMatches(stylesheet, UNIT_PX + ";")); int sum = UtilsMap.getSumOfValues(map); if (sum == 0) { return "px"; } return UtilsMap.getKeyOfHighestValue(map); }