List of usage examples for java.util HashMap get
public V get(Object key)
From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscConfig.java
/** * variable? ? value //w w w. ja v a 2s . c o m * * @param value ? * @return ? ? */ @SuppressWarnings("unchecked") private static String replaceValueByVariables(String value) { HashMap<String, String> variables = configuration.getVariables(); Iterator<String> iterator = variables.keySet().iterator(); String key = ""; String keyval = ""; String repkeyval = ""; while (iterator.hasNext()) { key = (String) iterator.next(); keyval = "${".concat(key).concat("}"); repkeyval = "\\$\\{".concat(key).concat("\\}"); if (value.indexOf(keyval) != -1) { value = value.replaceAll(repkeyval, variables.get(key)); break; } } return value; }
From source file:com.clustercontrol.hinemosagent.util.AgentConnectUtil.java
/** * [Topic]//from w ww . ja v a2 s. c om * ID?????? * @param facilityId * @return */ public static ArrayList<TopicInfo> getTopic(String facilityId) { ArrayList<TopicInfo> ret = null; m_log.debug("getJobOrder : " + facilityId); try { _agentTopicCacheLock.writeLock(); HashMap<String, List<TopicInfo>> topicMap = getAgentTopicCache(); List<TopicInfo> tmpInfoList = topicMap.get(facilityId); if (tmpInfoList != null) { ret = new ArrayList<TopicInfo>(); for (TopicInfo topicInfo : tmpInfoList) { if (topicInfo.isValid()) { ret.add(topicInfo); } else { m_log.info("topic is too old : " + topicInfo.toString()); } } topicMap.put(facilityId, new ArrayList<TopicInfo>()); storeAgentTopicCache(topicMap); } } finally { _agentTopicCacheLock.writeUnlock(); } return ret; }
From source file:com.clustercontrol.repository.util.FacilityTreeCache.java
private static boolean isFacilityReadable(String facilityId, String roleId) { // ????????????????????????? // (?????????????????????????) HashMap<String, ArrayList<FacilityTreeItem>> facilityTreeItemCache = getFacilityTreeItemCache(); List<FacilityTreeItem> treeItemList = facilityTreeItemCache.get(facilityId); if (treeItemList != null && !treeItemList.isEmpty()) { for (FacilityTreeItem item : treeItemList) { m_log.debug("item=" + item.getData().getFacilityId()); if (item.getAuthorizedRoleIdSet().contains(roleId)) { return true; }/*from w w w. ja v a 2 s . co m*/ } } return false; }
From source file:LineageSimulator.java
/** * Sample from a binomial with mean = true freq(f) and variance f(1-f)/coverage + sequencing noise *//*from www . ja va2 s . co m*/ public static HashMap<Mutation.SNV, double[]> addNoise(HashMap<Mutation.SNV, double[]> multiSampleFrequencies, int coverage, int numSamples) { HashMap<Mutation.SNV, double[]> noisyMultiSampleFrequencies = new HashMap<Mutation.SNV, double[]>(); for (Mutation.SNV snv : multiSampleFrequencies.keySet()) { noisyMultiSampleFrequencies.put(snv, new double[numSamples]); for (int i = 1; i < numSamples; i++) { int nReadsSNV = 0; if (multiSampleFrequencies.get(snv)[i] > 0) { BinomialGenerator b1 = new BinomialGenerator(coverage, multiSampleFrequencies.get(snv)[i], new Random()); nReadsSNV = b1.nextValue(); } int nReadsRef = coverage - nReadsSNV; // add sequencing noise int nSNV = 0; if (nReadsSNV > 0) { BinomialGenerator snvR = new BinomialGenerator(nReadsSNV, 1 - Parameters.SEQUENCING_ERROR, new Random()); nSNV += snvR.nextValue(); } BinomialGenerator flipR = new BinomialGenerator(nReadsRef, ((double) 1 / 3) * Parameters.SEQUENCING_ERROR, new Random()); nSNV += flipR.nextValue(); noisyMultiSampleFrequencies.get(snv)[i] = (double) nSNV / coverage; } } return noisyMultiSampleFrequencies; }
From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java
/** * Se encarga del proceso de exportacin de un plan de refactorizaciones * dinmicas./* w w w . ja va 2 s. c o m*/ * * @param destination * directorio a donde se quiere exportar el plan. * @throws IOException * IOException. * @throws XMLRefactoringReaderException * XMLRefactoringReaderException. */ public static void exportRefactoringPlan(String destination) throws IOException, XMLRefactoringReaderException { if (new File(destination + "/refactoringPlan").exists()) { //$NON-NLS-1$ FileManager.emptyDirectories(destination + "/refactoringPlan"); //$NON-NLS-1$ FileManager.deleteDirectories(destination + "/refactoringPlan", true); //$NON-NLS-1$ } // Creamos el directorio donde se guardar el plan. FileUtils.forceMkdir(new File(destination + "/refactoringPlan")); //$NON-NLS-1$ // Copiamos el fichero xml que guarda la informacin relativa al plan. FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_FILE), new File(destination + "/refactoringPlan/" //$NON-NLS-1$ + new File(RefactoringConstants.REFACTORING_PLAN_FILE).getName())); FileManager.copyFile(new File(RefactoringConstants.REFACTORING_PLAN_DTD), new File(destination + "/refactoringPlan/" //$NON-NLS-1$ + new File(RefactoringConstants.REFACTORING_PLAN_DTD).getName())); // Creamos una carpeta donde guardaremos las refactorizaciones. String refactoringDestination = destination + "/refactoringPlan/refactorings"; //$NON-NLS-1$ FileUtils.forceMkdir(new File(refactoringDestination)); // Pasamos a exportar las refactorizaciones necesarias dentro de la // carpeta anterior. ArrayList<String> refactorings = RefactoringPlanReader.readAllRefactoringsFromThePlan(); HashMap<String, String> allRefactorings = DynamicRefactoringLister.getInstance() .getDynamicRefactoringNameList(RefactoringPlugin.getDynamicRefactoringsDir(), true, null); allRefactorings.putAll(DynamicRefactoringLister.getInstance().getDynamicRefactoringNameList( RefactoringPlugin.getNonEditableDynamicRefactoringsDir(), true, null)); for (String next : refactorings) { String key = next + " (" + next + ".xml)"; //$NON-NLS-1$ //$NON-NLS-2$ String definition = allRefactorings.get(key);// ruta del fichero de // definicin de al // refactorizacin exportRefactoring(refactoringDestination, definition, true); } }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, HttpEntity entity, HashMap<String, String> headers) { HttpPost post = null;/*from w w w .j ava 2 s. c o m*/ HttpResponse response = null; HTTPResponse httpResponse = new HTTPResponse(); CloseableHttpClient httpclient = null; try { httpclient = (CloseableHttpClient) createHttpClient(); post = new HttpPost(url); post.setEntity(entity); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken); response = httpclient.execute(post); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException e) { e.printStackTrace(); } StringBuffer result = new StringBuffer(); String line = ""; try { while ((line = rd.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } httpResponse.setResponseCode(response.getStatusLine().getStatusCode()); httpResponse.setResponse(result.toString()); try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } return httpResponse; }
From source file:edu.ku.brc.specify.tasks.services.PickListUtils.java
/** * @param localizableIO/* w ww .j av a 2s . c o m*/ * @param collection * @return */ public static boolean importPickLists(final LocalizableIOIFace localizableIO, final Collection collection) { // Apply is Import All PickLists FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString(getI18n("PL_IMPORT")), FileDialog.LOAD); dlg.setDirectory(UIRegistry.getUserHomeDir()); dlg.setFile(getPickListXMLName()); UIHelper.centerAndShow(dlg); String dirStr = dlg.getDirectory(); String fileName = dlg.getFile(); if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) { return false; } final String path = dirStr + fileName; File file = new File(path); if (!file.exists()) { UIRegistry.showLocalizedError(getI18n("PL_FILE_NOT_EXIST"), file.getAbsoluteFile()); return false; } List<BldrPickList> bldrPickLists = DataBuilder.getBldrPickLists(null, file); Integer cnt = null; boolean wasErr = false; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); HashMap<String, PickList> plHash = new HashMap<String, PickList>(); List<PickList> items = getPickLists(localizableIO, true, false); for (PickList pl : items) { plHash.put(pl.getName(), pl); //System.out.println("["+pl.getName()+"]"); } for (BldrPickList bpl : bldrPickLists) { PickList pickList = plHash.get(bpl.getName()); //System.out.println("["+bpl.getName()+"]["+(pickList != null ? pickList.getName() : "null") + "]"); if (pickList == null) { // External PickList is new pickList = createPickList(bpl, collection); session.saveOrUpdate(pickList); if (cnt == null) cnt = 0; cnt++; } else if (!pickListsEqual(pickList, bpl)) { session.delete(pickList); collection.getPickLists().remove(pickList); pickList = createPickList(bpl, collection); session.saveOrUpdate(pickList); collection.getPickLists().add(pickList); if (cnt == null) cnt = 0; cnt++; } } session.commit(); } catch (Exception ex) { wasErr = true; if (session != null) session.rollback(); ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(PickListEditorDlg.class, ex); } finally { if (session != null) { session.close(); } } String key = wasErr ? "PL_ERR_IMP" : cnt != null ? "PL_WASIMPORT" : "PL_MATCHIMP"; UIRegistry.displayInfoMsgDlgLocalized(getI18n(key), cnt); return true; }
From source file:com.wormsim.utils.Utils.java
public static SimulationCommands readCommandLine(String[] p_args) throws IllegalArgumentException { // Convert the arguments into command lists HashMap<String, List<String>> data = new HashMap<>(p_args.length); String current_cmd = null;/*from w w w . ja va2 s.c o m*/ for (String arg : p_args) { if (arg.startsWith("-")) { current_cmd = arg; if (data.putIfAbsent(arg, new ArrayList<>(2)) != null) { throw new IllegalArgumentException("Repeated Argument: " + arg); } } else if (current_cmd != null) { data.get(current_cmd).add(arg); } else { throw new IllegalArgumentException("First Parameter must be Argument: " + arg); } } // Check if any of the commands are something to act upon right now, like help. // WARNING: Hard Coded Parameters. if (data.containsKey("-h") || data.containsKey("--help")) { // Print out the help and then terminate, although the other arguments should // also be checked to see if they are relevant. help(); System.exit(0); // Generally not recommended, but should be fine here. // TODO: Detailed information as per argument for help? } SimulationCommands cmds = new SimulationCommands(data); return cmds; }
From source file:org.wso2.mdm.qsg.utils.HTTPInvoker.java
public static HTTPResponse sendHTTPPostWithURLParams(String url, List<NameValuePair> params, HashMap<String, String> headers) { HttpPost post = null;/*from w ww. j a v a 2 s. c o m*/ HttpResponse response = null; CloseableHttpClient httpclient = null; HTTPResponse httpResponse = new HTTPResponse(); try { httpclient = (CloseableHttpClient) createHttpClient(); post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(params)); for (String key : headers.keySet()) { post.setHeader(key, headers.get(key)); } response = httpclient.execute(post); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); } catch (IOException e) { e.printStackTrace(); } StringBuffer result = new StringBuffer(); String line = ""; try { while ((line = rd.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } httpResponse.setResponseCode(response.getStatusLine().getStatusCode()); httpResponse.setResponse(result.toString()); return httpResponse; }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> findRepeatedFreq(String input) { HashMap repeatedCount = new HashMap<String, Integer>(); for (int i = 0; i < input.length(); i++) { if (i + 1 < input.length() && input.charAt(i) == input.charAt(i + 1)) { String key = String.valueOf(input.charAt(i)) + String.valueOf(input.charAt(i + 1)); if (!repeatedCount.containsKey(key)) { repeatedCount.put(key, 1); } else { int tempCount = (int) repeatedCount.get(key); tempCount++;/*from w w w . j a va2 s. co m*/ repeatedCount.put(key, tempCount); } } } return sortByValue(repeatedCount); }