List of usage examples for java.util LinkedHashMap entrySet
public Set<Map.Entry<K, V>> entrySet()
From source file:Simulator.PerformanceCalculation.java
public JPanel waitTime2() { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime2()); wait1.put(traceObject.getSurgeonId(), details); } else {/* w w w.j ava 2s . co m*/ wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2()); } no.add(traceObject.getSurgeonId()); } String[] column = new String[no.size()]; String series1 = "Wait Time 2"; for (int i = 0; i < no.size(); i++) { column[i] = "Surgeon " + (i + 1); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double total = 0; for (Double double1 : arrayList) { total += double1; } average.put(integer, total / arrayList.size()); } for (int i = 1; i <= average.size(); i++) { dataset.addValue(Math.round(average.get(i) / 600), series1, column[i - 1]); } JFreeChart chart = ChartFactory.createBarChart("Wait Time 2", // chart title "Surgeon ID", // domain axis label "Days", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); return new ChartPanel(chart); }
From source file:com.opengamma.analytics.financial.interestrate.MultipleYieldCurveFinderDataBundle.java
/** * Create a MultipleYieldCurveFinderDataBundle where the number of nodes and the list of curve names correspond to all the curves (known curves and curves still to be calibrated). * This constructor is used to compute the extended Jacobian matrix when curves are calibrated in several blocks. * @param derivatives The list of instruments used in the calibration. * @param marketValues The market value of the instruments. * @param knownCurves The curves already calibrated. * @param unknownCurveNodePoints The node points of the new curves to calibrate. * @param unknownCurveInterpolators The interpolators of the new curves to calibrate. * @param useFiniteDifferenceByDefault Flag for using the finite difference computation of the Jacobian. * @param fxMatrix The FX Matrix with the required exchange rates. * @return The data bundle./*from www . jav a2 s . c om*/ */ public static MultipleYieldCurveFinderDataBundle withAllCurves(final List<InstrumentDerivative> derivatives, final double[] marketValues, final YieldCurveBundle knownCurves, final LinkedHashMap<String, double[]> unknownCurveNodePoints, final LinkedHashMap<String, Interpolator1D> unknownCurveInterpolators, final boolean useFiniteDifferenceByDefault, final FXMatrix fxMatrix) { // Argument checker: start ArgumentChecker.notNull(derivatives, "derivatives"); ArgumentChecker.noNulls(derivatives, "derivatives"); ArgumentChecker.notNull(marketValues, "market values null"); ArgumentChecker.notNull(unknownCurveNodePoints, "unknown curve node points"); ArgumentChecker.notNull(unknownCurveInterpolators, "unknown curve interpolators"); ArgumentChecker.notEmpty(unknownCurveNodePoints, "unknown curve node points"); ArgumentChecker.notEmpty(unknownCurveInterpolators, "unknown curve interpolators"); ArgumentChecker.isTrue(derivatives.size() == marketValues.length, "marketValues wrong length; must be one par rate per derivative (have {} values for {} derivatives", marketValues.length, derivatives.size()); ArgumentChecker.notNull(fxMatrix, "FX matrix"); if (knownCurves != null) { for (final String name : knownCurves.getAllNames()) { if (unknownCurveInterpolators.containsKey(name)) { throw new IllegalArgumentException("Curve name in known set matches one to be solved for"); } } } if (unknownCurveNodePoints.size() != unknownCurveInterpolators.size()) { throw new IllegalArgumentException("Number of unknown curves not the same as curve interpolators"); } // Argument checker: end int nbNodes = 0; if (knownCurves != null) { for (final String name : knownCurves.getAllNames()) { nbNodes += knownCurves.getCurve(name).getNumberOfParameters(); } } for (final double[] nodes : unknownCurveNodePoints.values()) { // Nodes from new curves nbNodes += nodes.length; } final List<String> names = new ArrayList<>(); if (knownCurves != null) { names.addAll(knownCurves.getAllNames()); // Names from existing curves } final Iterator<Entry<String, double[]>> nodePointsIterator = unknownCurveNodePoints.entrySet().iterator(); final Iterator<Entry<String, Interpolator1D>> unknownCurvesIterator = unknownCurveInterpolators.entrySet() .iterator(); while (nodePointsIterator.hasNext()) { // Names from new curves final Entry<String, double[]> entry1 = nodePointsIterator.next(); final Entry<String, Interpolator1D> entry2 = unknownCurvesIterator.next(); final String name1 = entry1.getKey(); if (!name1.equals(entry2.getKey())) { throw new IllegalArgumentException("Names must be the same"); } ArgumentChecker.notNull(entry1.getValue(), "curve node points for " + name1); ArgumentChecker.notNull(entry2.getValue(), "interpolator for " + name1); names.add(name1); } return new MultipleYieldCurveFinderDataBundle(derivatives, marketValues, knownCurves, unknownCurveNodePoints, unknownCurveInterpolators, useFiniteDifferenceByDefault, fxMatrix, nbNodes, names); }
From source file:com.glaf.core.service.impl.MxTablePageServiceImpl.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Object> getTableList(String tableName, String idColumn, Map<String, String> selectColumns, int begin, int pageSize, List<QueryCondition> conditions, LinkedHashMap<String, Boolean> orderByColumns) { SqlExecutor sqlExecutor = QueryUtils.getMyBatisAndConditionSql(conditions); StringBuilder buffer = new StringBuilder(); buffer.append(" select "); if (selectColumns != null && !selectColumns.isEmpty()) { Set<Entry<String, String>> entrySet = selectColumns.entrySet(); for (Entry<String, String> entry : entrySet) { String columnName = entry.getKey(); String columnLabel = entry.getValue(); if (columnName != null && columnLabel != null) { buffer.append(columnName).append(" as ").append(columnLabel); buffer.append(" , "); }/* w w w . j a v a2 s . c o m*/ } buffer.delete(buffer.length() - 2, buffer.length()); buffer.append(" from ").append(tableName); } else { buffer.append(" * from ").append(tableName); } buffer.append(" where 1=1 "); String sql = buffer.toString() + sqlExecutor.getSql(); if (orderByColumns != null && !orderByColumns.isEmpty()) { buffer.delete(0, buffer.length()); buffer.append(" order by "); Set<Entry<String, Boolean>> entrySet = orderByColumns.entrySet(); for (Entry<String, Boolean> entry : entrySet) { String columnName = entry.getKey(); Boolean ordinal = entry.getValue(); if (columnName != null && ordinal != null) { buffer.append(columnName); if (ordinal.booleanValue()) { buffer.append(" asc"); } else { buffer.append(" desc"); } buffer.append(" ,"); } } if (buffer.toString().endsWith(",")) { buffer.delete(buffer.length() - 2, buffer.length()); } } sql = sql + buffer.toString(); Map<String, Object> params = new java.util.HashMap<String, Object>(); if (sqlExecutor.getParameter() instanceof Map) { params.putAll((Map) sqlExecutor.getParameter()); } logger.debug("sql:\n" + sql); logger.debug("params:" + params); params.put("queryString", sql); if (begin < 0) { begin = 0; } if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; } RowBounds rowBounds = new RowBounds(begin, pageSize); List<Object> rows = sqlSession.selectList("getSqlQueryList", params, rowBounds); return rows; }
From source file:me.piebridge.bible.Bible.java
private String getOsis(String book, ArrayList<LinkedHashMap<String, String>> maps) { // test osis/*from w w w .j a va 2 s.c o m*/ if (maps.size() > 0) { for (String osis : maps.get(0).values()) { if (osis.equalsIgnoreCase(book)) { return osis; } } } book = book.toLowerCase(Locale.US).replace(" ", ""); // prefer fullname for (LinkedHashMap<String, String> map : maps) { for (Entry<String, String> entry : map.entrySet()) { if (entry.getKey().toLowerCase(Locale.US).replace(" ", "").equals(book)) { return entry.getValue(); } } } // prefer startswith for (LinkedHashMap<String, String> map : maps) { for (Entry<String, String> entry : map.entrySet()) { if (entry.getKey().toLowerCase(Locale.US).replace(" ", "").startsWith(book)) { return entry.getValue(); } } } // prefer contains for (LinkedHashMap<String, String> map : maps) { for (Entry<String, String> entry : map.entrySet()) { if (entry.getKey().toLowerCase(Locale.US).replace(" ", "").contains(book)) { return entry.getValue(); } } } return null; }
From source file:org.oxymores.chronix.engine.RunnerShell.java
public static RunResult run(RunDescription rd, String logFilePath, boolean storeLogFile, boolean returnFullerLog) { RunResult res = new RunResult(); Process p;/* ww w . ja v a 2s . c o m*/ String nl = System.getProperty("line.separator"); Pattern pat = Pattern.compile("^set ([a-zA-Z]+[a-zA-Z0-9]*)=(.+)"); Matcher matcher = pat.matcher("Testing123Testing"); String encoding = getEncoding(rd); log.debug("Encoding is " + encoding); // /////////////////////////// // Build command List<String> argsStrings = buildCommand(rd); // ///////////////////////////////////////////////////////////////////////// // Create a process builder with the command line contained in the array ProcessBuilder pb = new ProcessBuilder(argsStrings); // Mix stdout and stderr (easier to put errors in context this way) pb.redirectErrorStream(true); // Create array containing environment Map<String, String> env = pb.environment(); for (int i = 0; i < rd.getEnvNames().size(); i++) { env.put(rd.getEnvNames().get(i), rd.getEnvValues().get(i)); } BufferedReader br = null; Writer output = null; try { // Start! log.debug("GO (" + rd.getSubMethod() + ")"); p = pb.start(); // Read output (err & out), write it to file InputStreamReader isr = new InputStreamReader(p.getInputStream(), encoding); br = new BufferedReader(isr); String line = null; int i = 0; LinkedHashMap<Integer, String> endBuffer = new LinkedHashMap<Integer, String>() { private static final long serialVersionUID = -6773540176968046737L; @Override protected boolean removeEldestEntry(java.util.Map.Entry<Integer, String> eldest) { return this.size() > Constants.MAX_RETURNED_BIG_LOG_END_LINES; } }; if (storeLogFile) { output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFilePath), "UTF-8")); } line = br.readLine(); while (line != null) { i++; // Local log file gets all lines if (storeLogFile) { output.write(line + nl); } // Small log gets first 500 lines or 10000 characters (the smaller of the two) if (i < Constants.MAX_RETURNED_SMALL_LOG_LINES && res.logStart.length() < Constants.MAX_RETURNED_SMALL_LOG_CHARACTERS) { res.logStart += nl + line; } // Scheduler internal log gets first line only if (i == 1) { log.debug(String.format("Job running. First line of output is: %s", line)); } // Fuller log gets first 10k lines, then last 1k lines. if (returnFullerLog) { if (i < Constants.MAX_RETURNED_BIG_LOG_LINES) { res.fullerLog += line; } else { endBuffer.put(i, line); } } // Analysis: there may be a new variable definition in the line matcher.reset(line); if (matcher.find()) { log.debug("Key detected :" + matcher.group(1)); log.debug("Value detected :" + matcher.group(2)); res.newEnvVars.put(matcher.group(1), matcher.group(2)); } line = br.readLine(); } IOUtils.closeQuietly(br); if (i > Constants.MAX_RETURNED_BIG_LOG_LINES && i < Constants.MAX_RETURNED_BIG_LOG_LINES + Constants.MAX_RETURNED_BIG_LOG_END_LINES && returnFullerLog) { res.fullerLog += Arrays.toString(endBuffer.entrySet().toArray()); } if (i >= Constants.MAX_RETURNED_BIG_LOG_LINES + Constants.MAX_RETURNED_BIG_LOG_END_LINES && returnFullerLog) { res.fullerLog += "\n\n\n*******\n LOG TRUNCATED - See full log on server\n********\n\n\n" + Arrays.toString(endBuffer.entrySet().toArray()); } // Done: close log file if (storeLogFile) { IOUtils.closeQuietly(output); File f = new File(logFilePath); res.logSizeBytes = f.length(); } } catch (IOException e) { log.error("error occurred while running job", e); res.logStart = e.getMessage(); res.returnCode = -1; IOUtils.closeQuietly(br); IOUtils.closeQuietly(output); return res; } // Return res.returnCode = p.exitValue(); res.logPath = logFilePath; res.envtUser = System.getProperty("user.name"); try { res.envtServer = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { res.envtServer = "unknown"; } log.info(String.format("Job ended, RC is %s", res.returnCode)); return res; }
From source file:Simulator.PerformanceCalculation.java
public JPanel waitTime() { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime1()); details.add(traceObject.getWaitTime2()); wait1.put(traceObject.getSurgeonId(), details); } else {/* w w w . jav a 2 s . c om*/ wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1()); wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2()); } no.add(traceObject.getSurgeonId()); } String[] column = new String[no.size()]; String series1 = "Wait Time"; for (int i = 0; i < no.size(); i++) { column[i] = "Surgeon " + (i + 1); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double total = 0; for (Double double1 : arrayList) { total += double1; } average.put(integer, total / (arrayList.size() / 2)); } for (int i = 1; i <= average.size(); i++) { dataset.addValue(Math.round(average.get(i) / 600), series1, column[i - 1]); } JFreeChart chart = ChartFactory.createBarChart("Wait Time", // chart title "Surgeon ID", // domain axis label "Days", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); return new ChartPanel(chart); }
From source file:io.hops.hopsworks.api.jupyter.URITemplateProxyServlet.java
@Override protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { //First collect params /*/*w w w. ja v a 2s . c o m*/ * Do not use servletRequest.getParameter(arg) because that will * typically read and consume the servlet InputStream (where our * form data is stored for POST). We need the InputStream later on. * So we'll parse the query string ourselves. A side benefit is * we can keep the proxy parameters in the query string and not * have to add them to a URL encoded form attachment. */ String queryString = "?" + servletRequest.getQueryString();//no "?" but might have "#" int hash = queryString.indexOf('#'); if (hash >= 0) { queryString = queryString.substring(0, hash); } List<NameValuePair> pairs; try { //note: HttpClient 4.2 lets you parse the string without building the URI pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8"); } catch (URISyntaxException e) { throw new ServletException("Unexpected URI parsing error on " + queryString, e); } LinkedHashMap<String, String> params = new LinkedHashMap<>(); for (NameValuePair pair : pairs) { params.put(pair.getName(), pair.getValue()); } //Now rewrite the URL StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate); while (matcher.find()) { String arg = matcher.group(1); String replacement = params.remove(arg);//note we remove if (replacement != null) { matcher.appendReplacement(urlBuf, replacement); port = replacement; } else if (port != null) { matcher.appendReplacement(urlBuf, port); } else { throw new ServletException("Missing HTTP parameter " + arg + " to fill the template"); } } matcher.appendTail(urlBuf); String newTargetUri = urlBuf.toString(); servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri); try { targetUriObj = new URI(newTargetUri); } catch (Exception e) { throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e); } servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj)); //Determine the new query string based on removing the used names StringBuilder newQueryBuf = new StringBuilder(queryString.length()); for (Map.Entry<String, String> nameVal : params.entrySet()) { if (newQueryBuf.length() > 0) { newQueryBuf.append('&'); } newQueryBuf.append(nameVal.getKey()).append('='); if (nameVal.getValue() != null) { newQueryBuf.append(nameVal.getValue()); } } servletRequest.setAttribute(ATTR_QUERY_STRING, newQueryBuf.toString()); // Create Exchange object with targetUriObj // create transport object // ServiceProxy sp = new ServiceProxy(); // sp.setTargetUrl(ATTR_TARGET_URI); // super.service(servletRequest, servletResponse); // RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config. // getServletContext(), getProxiesXmlLocation(config)); }
From source file:org.ireland.jnetty.webapp.WebApp.java
public void parseWebXml() throws ServletException { log.debug("parseing webXml."); WebXmlLoader loader = new WebXmlLoader(this); try {//from w w w .j a va2s. c o m // <context-param>? loader.loadInitParam(); // <listener> loader.loadListener(); // web.xml<filter> LinkedHashMap<String, FilterConfigImpl> filterConfigMap = loader.praseFilter(); for (Entry<String, FilterConfigImpl> e : filterConfigMap.entrySet()) { addFilter(e.getValue()); } // web.xml<filter-mapping> loader.parseFilterMapping(filterConfigMap); // web.xml<servlet> LinkedHashMap<String, ServletConfigImpl> servletConfigMap = loader.praseServletConfig(); // web.xml<servlet-mapping> loader.parseServletMapping(servletConfigMap); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:Simulator.PerformanceCalculation.java
private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime1()); details.add(traceObject.getWaitTime2()); wait1.put(traceObject.getSurgeonId(), details); } else {//from ww w . ja va 2 s .c om wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1()); wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2()); } no.add(traceObject.getSurgeonId()); } String[] column = new String[no.size()]; String series1 = "Minimum Cost"; String series2 = "Acceptable Cost"; String series3 = "Actual Cost"; for (int i = 0; i < no.size(); i++) { column[i] = "Surgeon " + (i + 1); } LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double total = 0; for (Double double1 : arrayList) { total += double1; } average.put(integer, total / 600); } for (int i = 1; i <= average.size(); i++) { int costMin = (Configuration.minimumSurgeryTime * (wait1.get(i).size() / 2) * Configuration.costOfPatientWaiting); int costAccept = (Configuration.acceptedSurgeryTime * (wait1.get(i).size() / 2) * Configuration.costOfPatientWaiting); int actualCost = (int) Math.round(average.get(i) * Configuration.costOfPatientWaiting); int x = actualCost - (costAccept + costMin); if (x > actualCost) { x = actualCost; } dataset.addValue(costMin, series1, column[i - 1]); dataset.addValue(costAccept - costMin, series2, column[i - 1]); dataset.addValue(x, series3, column[i - 1]); } return dataset; }
From source file:Simulator.PerformanceCalculation.java
public JPanel costAnaylsis() { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime1()); details.add(traceObject.getWaitTime2()); wait1.put(traceObject.getSurgeonId(), details); } else {// www .j a va2s.co m wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1()); wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2()); } no.add(traceObject.getSurgeonId()); } String[] column = new String[no.size()]; String series1 = "Cost"; for (int i = 0; i < no.size(); i++) { column[i] = "Surgeon " + (i + 1); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int totalCost = 0; LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double total = 0; for (Double double1 : arrayList) { total += double1; } totalCost += total * Configuration.costOfPatientWaiting; average.put(integer, total / 600); } for (int i = 1; i <= average.size(); i++) { dataset.addValue(Math.round(average.get(i) * Configuration.costOfPatientWaiting), series1, column[i - 1]); } totalCostClass = totalCost; JFreeChart chart = ChartFactory.createBarChart("Cost", // chart title "Surgeon ID", // domain axis label "$", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); return new ChartPanel(chart); }