List of usage examples for java.util HashMap get
public V get(Object key)
From source file:com.astamuse.asta4d.data.InjectUtil.java
private static ContextDataHolder findValueForTarget(TargetInfo targetInfo, Class overrideSearchType) throws DataOperationException { Context context = Context.getCurrentThreadContext(); ContextDataFinder dataFinder = Configuration.getConfiguration().getContextDataFinder(); Class searchType = overrideSearchType == null ? targetInfo.type : overrideSearchType; ContextDataHolder valueHolder = dataFinder.findDataInContext(context, targetInfo.scope, targetInfo.name, searchType);//from w w w. java2 s . co m if (valueHolder == null && targetInfo.contextDataSetFactory != null) { Object value; if (targetInfo.isContextDataSetSingletonInContext) { // this map was initialized when the context was initialized HashMap<String, Object> cdSetSingletonMap = context.getData(ContextDataSetSingletonMapKey); // we must synchronize it to avoid concurrent access on the map synchronized (cdSetSingletonMap) { String clsName = targetInfo.type.getName(); value = cdSetSingletonMap.get(clsName); if (value == null) { value = targetInfo.contextDataSetFactory.createInstance(targetInfo.type); injectToInstance(value); cdSetSingletonMap.put(clsName, value); } } } else { value = targetInfo.contextDataSetFactory.createInstance(targetInfo.type); injectToInstance(value); } valueHolder = new ContextDataHolder(targetInfo.name, targetInfo.scope, value); } else if (valueHolder == null) { valueHolder = new ContextDataHolder(targetInfo.name, ContextDataNotFoundScope, targetInfo.defaultValue); } return valueHolder; }
From source file:com.krawler.esp.servlets.SuperAdminServlet.java
public static String editCompany(Connection conn, HttpServletRequest request, HttpServletResponse response) throws ServiceException { String status = ""; DiskFileUpload fu = new DiskFileUpload(); JSONObject j = new JSONObject(); JSONObject j1 = new JSONObject(); List fileItems = null;/* ww w. j a v a2 s. com*/ FileItem fi1 = null; try { fileItems = fu.parseRequest(request); } catch (FileUploadException e) { throw ServiceException.FAILURE("SuperAdminHandler.editCompany", e); } HashMap arrParam = new HashMap(); for (Iterator k = fileItems.iterator(); k.hasNext();) { fi1 = (FileItem) k.next(); arrParam.put(fi1.getFieldName(), fi1.getString()); } try { DbUtil.executeUpdate(conn, "update company set companyname=?, address=?, city=?, state=?, country=?, phone=?, fax=?, " + "zip=?, timezone=?, website=? where companyid=?;", new Object[] { arrParam.get("companyname"), arrParam.get("address"), arrParam.get("city"), arrParam.get("state"), arrParam.get("country"), arrParam.get("phone"), arrParam.get("fax"), arrParam.get("zip"), arrParam.get("timezone"), arrParam.get("website"), arrParam.get("companyid") }); j.put("companyname", arrParam.get("companyname")); j.put("address", arrParam.get("address")); j.put("city", arrParam.get("city")); j.put("state", arrParam.get("state")); j.put("country", arrParam.get("country")); j.put("phone", arrParam.get("phone")); j.put("fax", arrParam.get("fax")); j.put("zip", arrParam.get("zip")); j.put("timezone", arrParam.get("timezone")); j.put("website", arrParam.get("website")); j.put("companyid", arrParam.get("companyid")); if (arrParam.get("image").toString().length() != 0) { genericFileUpload uploader = new genericFileUpload(); try { uploader.doPost(fileItems, arrParam.get("companyid").toString(), StorageHandler.GetProfileImgStorePath()); } catch (ConfigurationException e) { throw ServiceException.FAILURE("SuperAdminHandler.createCompany", e); } if (uploader.isUploaded()) { DbUtil.executeUpdate(conn, "update company set image=? where companyid = ?", new Object[] { ProfileImageServlet.ImgBasePath + arrParam.get("companyid").toString() + uploader.getExt(), arrParam.get("companyid") }); j.put("image", arrParam.get("companyid") + uploader.getExt()); } } j1.append("data", j); status = j1.toString(); } catch (JSONException e) { status = "failure"; throw ServiceException.FAILURE("SuperAdminHandler.editCompany", e); } return status; }
From source file:org.easyrec.utils.MyUtils.java
/** * This function sorts the Strings in the given list by their first * occurrence in the given text. The Strings in the list are tokenized * e.g. "red bull" is split in "red" and "bull" those tokens are * matched by their first occurrence in the text. *//*ww w.ja v a 2 s .c om*/ public static List<String> orderByFuzzyFirstOccurenceInText(String listToOrder[], String textToParse) { List<String> sortedList = new ArrayList<String>(); HashMap<Integer, String> h = new HashMap<Integer, String>(); if (listToOrder != null && !textToParse.equals("")) { for (String stringTokens : listToOrder) { String[] tokens = stringTokens.split(" "); for (String token : tokens) { if (textToParse.indexOf(token) > 0 && token.length() > 3) { h.put(textToParse.indexOf(token), token); } } } List<Integer> keys = new ArrayList<Integer>(h.keySet()); Collections.sort(keys); for (Integer k : keys) { sortedList.add(h.get(k)); } } return sortedList; }
From source file:pt.webdetails.cpf.SimpleContentGenerator.java
/** * Get a map of all public methods with the Exposed annotation. * Map is not thread-safe and should be used read-only. * @param classe Class where to find methods * @param log classe's logger//from www. j a va 2 s . c o m * @param lowerCase if keys should be in lower case. * @return map of all public methods with the Exposed annotation */ protected static Map<String, Method> getExposedMethods(Class<?> classe, boolean lowerCase) { HashMap<String, Method> exposedMethods = new HashMap<String, Method>(); Log log = LogFactory.getLog(classe); for (Method method : classe.getMethods()) { if (method.getAnnotation(Exposed.class) != null) { String methodKey = method.getName().toLowerCase(); if (exposedMethods.containsKey(methodKey)) { log.error("Method " + method + " differs from " + exposedMethods.get(methodKey) + " only in case and will override calls to it!!"); } log.debug("registering " + classe.getSimpleName() + "." + method.getName()); exposedMethods.put(methodKey, method); } } return exposedMethods; }
From source file:com.siemens.sw360.importer.ComponentImportUtils.java
@Nullable private static List<AttachmentContent> getAttachmentContents( HashMap<String, List<String>> releaseIdentifierToDownloadURL, ImmutableMap<String, AttachmentContent> URLtoAttachment, String releaseIdentifier) { List<AttachmentContent> attachmentContents = null; if (releaseIdentifierToDownloadURL.containsKey(releaseIdentifier)) { final List<String> URLs = releaseIdentifierToDownloadURL.get(releaseIdentifier); attachmentContents = new ArrayList<>(URLs.size()); for (String url : URLs) { if (URLtoAttachment.containsKey(url)) { final AttachmentContent attachmentContent = URLtoAttachment.get(url); attachmentContents.add(attachmentContent); }/*ww w. j a va 2 s.c om*/ } } return attachmentContents; }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> findDigraphFreq(String input) { HashMap digraphCount = new HashMap<String, Integer>(); for (int i = 0; i < input.length(); i++) { if (i + 1 < input.length()) { String key = String.valueOf(input.charAt(i)) + String.valueOf(input.charAt(i + 1)); if (!digraphCount.containsKey(key)) { digraphCount.put(key, 1); } else { int tempCount = (int) digraphCount.get(key); tempCount++;/*from w w w. j av a 2 s . co m*/ digraphCount.put(key, tempCount); } } } return sortByValue(digraphCount); }
From source file:com.clustercontrol.hinemosagent.util.AgentConnectUtil.java
/** * [Topic]/*from w w w . ja v a2 s .c om*/ * @param facilityId * @param info */ private static void subSetTopic(String facilityId, TopicInfo info) { List<TopicInfo> infoList = null; try { _agentTopicCacheLock.writeLock(); HashMap<String, List<TopicInfo>> topicMap = getAgentTopicCache(); infoList = topicMap.get(facilityId); if (infoList != null && infoList.contains(info)) { m_log.info("subSetTopic(): same topic. Maybe, agent timeout error occured. " + "facilityId = " + facilityId); return; } if (infoList == null) { infoList = new ArrayList<TopicInfo>(); topicMap.put(facilityId, infoList); } // Topic????????????? if (infoList.contains(info)) { m_log.info("subSetTopic(): same topic. Maybe, agent timeout error occured. " + "facilityId = " + facilityId); } else { infoList.add(info); if (infoList.size() > 10) { m_log.info("subSetTopic(): topicList is too large : size=" + infoList.size() + ", facilityId = " + facilityId); } } storeAgentTopicCache(topicMap); } finally { _agentTopicCacheLock.writeUnlock(); } printRunInstructionInfo(facilityId, infoList); }
From source file:com.example.common.ApiRequestFactory.java
/** * Generate the API JSON request body //from w w w .java 2 s .c o m */ @SuppressWarnings("unchecked") private static String generateJsonRequestBody(Object params) { if (params == null) { return ""; } HashMap<String, Object> requestParams; if (params instanceof HashMap) { requestParams = (HashMap<String, Object>) params; } else { return ""; } // add parameter node final Iterator<String> keySet = requestParams.keySet().iterator(); JSONObject jsonObject = new JSONObject(); try { while (keySet.hasNext()) { final String key = keySet.next(); jsonObject.put(key, requestParams.get(key)); } } catch (JSONException e) { e.printStackTrace(); return ""; } return jsonObject.toString(); }
From source file:marytts.server.http.MivoqSynthesisRequestHandler.java
private static void parseEffectsIntoHashMap(HashMap<String, ParamParser> registry, HashMap<String, Object> effects_values, JSONObject effects) { for (String name : JSONObject.getNames(effects)) { // System.out.println("----------"); // System.out.println(name); ParamParser parser = registry.get(name); if (parser != null) { Object param = parser.parse(effects.get(name)); // System.out.println(param); if (effects_values.containsKey(name)) { Object o = effects_values.get(name); param = parser.merge(o, param); }/*from w w w .j av a2 s. co m*/ // System.out.println(param); effects_values.put(name, param); } } }
From source file:free.yhc.netmbuddy.utils.Utils.java
public static <K, V> K findKey(HashMap<K, V> map, V value) { Iterator<K> iter = map.keySet().iterator(); while (iter.hasNext()) { K key = iter.next();/* w w w. j a v a2s. com*/ if (map.get(key).equals(value)) return key; } return null; }