List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.DispatchServ.java
/** JMTimer calls this method every time a period closes in the given session. The dispatcher * routes this request to the UpdateServ to inform the clients, and the ControlServ to update * the session data structures. Returns the response sent out by the UpdateServ. Before all this * notify the Trade Engine that the period has closed, and process any updates that it * generates (this happens predominantly in call markets, where all offers are processed upon * period closure *///from ww w . j a v a2 s .com public Response processPeriodClosure(int sessionId, int periodNum) { TradeEngine tradeServ = activeEngines.get(sessionId); UpdateBasket basket = tradeServ.processClosePeriod(sessionId); if (basket != null) { int periodTime = 0; int[] marketTime = new int[controlServ.getMarketTime(sessionId).length]; int openingTime = controlServ.getOpeningTime(sessionId); Vector tradeUpdates = basket.getTradeUpdates(); for (int i = 0; i < tradeUpdates.size(); i++) { TradeUpdate tupdate = (TradeUpdate) tradeUpdates.get(i); tupdate.setPeriodTime(periodTime); tupdate.setMarketTime(marketTime); tupdate.setOpeningTime(openingTime); } updateServ.sendTradeUpdates(periodNum, tradeUpdates); monitorServ.processTransactionUpdates(basket); } int[] recipients = controlServ.getSessionClients(sessionId); boolean lastPeriod = controlServ.closePeriod(sessionId); if (recipients == null) return null; PayoffUpdate pupdate = controlServ.calculatePayoffs(sessionId); float[] payoffs = pupdate.getPayoffs(); String[] masks = pupdate.getMasks(); EarningsInfo[] einfo = controlServ.getEarningsHistory(sessionId); if (lastPeriod) { updateServ.sendEndPeriodUpdate(recipients, periodNum, payoffs, masks, einfo, true); log.info("Subjects have completed all periods. Ending session in 30 seconds..."); terminateSession(sessionId, 30000); } else { log.info("Moving to the next period (period " + (periodNum + 1) + ")"); updateServ.sendEndPeriodUpdate(recipients, periodNum, payoffs, masks, einfo, false); if (!controlServ.getManualControl(sessionId)) { nextPeriod(sessionId); } } return null; }
From source file:org.smilec.smile.student.HttpMsgForStudent.java
public JSONArray vectortojsonarray(Vector<Integer> _arrayname) { JSONArray jsonarray = new JSONArray(); for (int i = 0; i < _arrayname.size(); i++) { try {//w w w.j a v a2s . c o m if (_arrayname.get(i) == null) jsonarray.put(i, 0); else jsonarray.put(i, _arrayname.get(i)); } catch (JSONException e) { Log.i(APP_TAG, "Transition error: Vector to JSONArray"); e.printStackTrace(); } } return jsonarray; }
From source file:fr.inrialpes.exmo.align.cli.ExtGroupEval.java
public void printHTML(Vector<Vector<Object>> result, PrintStream writer) { // variables for computing iterative harmonic means int expected = 0; // expected so far int foundVect[]; // found so far double symVect[]; // symmetric similarity double effVect[]; // effort-based similarity double precOrVect[]; // precision-oriented similarity double recOrVect[]; // recall-oriented similarity fsize = format.length();/*from w w w . j a v a2s .c om*/ try { Formatter formatter = new Formatter(writer); // Print the header writer.println("<html><head></head><body>"); writer.println("<table border='2' frame='sides' rules='groups'>"); writer.println("<colgroup align='center' />"); // for each algo <td spancol='2'>name</td> for (String m : listAlgo) { writer.println("<colgroup align='center' span='" + 2 * fsize + "' />"); } // For each file do a writer.println("<thead valign='top'><tr><th>algo</th>"); // for each algo <td spancol='2'>name</td> for (String m : listAlgo) { writer.println("<th colspan='" + ((2 * fsize)) + "'>" + m + "</th>"); } writer.println("</tr></thead><tbody><tr><td>test</td>"); // for each algo <td>Prec.</td><td>Rec.</td> for (String m : listAlgo) { for (int i = 0; i < fsize; i++) { if (format.charAt(i) == 's') { writer.println("<td colspan='2'><center>Symmetric</center></td>"); } else if (format.charAt(i) == 'e') { writer.println("<td colspan='2'><center>Effort</center></td>"); } else if (format.charAt(i) == 'p') { writer.println("<td colspan='2'><center>Prec. orient.</center></td>"); } else if (format.charAt(i) == 'r') { writer.println("<td colspan='2'><center>Rec. orient.</center></td>"); } } //writer.println("<td>Prec.</td><td>Rec.</td>"); } writer.println("</tr></tbody><tbody>"); foundVect = new int[size]; symVect = new double[size]; effVect = new double[size]; precOrVect = new double[size]; recOrVect = new double[size]; for (int k = size - 1; k >= 0; k--) { foundVect[k] = 0; symVect[k] = 0.; effVect[k] = 0.; precOrVect[k] = 0.; recOrVect[k] = 0.; } // </tr> // For each directory <tr> boolean colored = false; for (Vector<Object> test : result) { int nexpected = -1; if (colored == true && color != null) { colored = false; writer.println("<tr bgcolor=\"" + color + "\">"); } else { colored = true; writer.println("<tr>"); } ; // Print the directory <td>bla</td> writer.println("<td>" + (String) test.get(0) + "</td>"); // For each record print the values <td>bla</td> Enumeration<Object> f = test.elements(); f.nextElement(); for (int k = 0; f.hasMoreElements(); k++) { ExtPREvaluator eval = (ExtPREvaluator) f.nextElement(); if (eval != null) { // iterative H-means computation if (nexpected == -1) { nexpected = eval.getExpected(); expected += nexpected; } // If foundVect is -1 then results are invalid if (foundVect[k] != -1) foundVect[k] += eval.getFound(); for (int i = 0; i < fsize; i++) { writer.print("<td>"); if (format.charAt(i) == 's') { formatter.format("%1.2f", eval.getSymPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getSymRecall()); symVect[k] += eval.getSymSimilarity(); } else if (format.charAt(i) == 'e') { formatter.format("%1.2f", eval.getEffPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getEffRecall()); effVect[k] += eval.getEffSimilarity(); } else if (format.charAt(i) == 'p') { formatter.format("%1.2f", eval.getPrecisionOrientedPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getPrecisionOrientedRecall()); precOrVect[k] += eval.getPrecisionOrientedSimilarity(); } else if (format.charAt(i) == 'r') { formatter.format("%1.2f", eval.getRecallOrientedPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getRecallOrientedRecall()); recOrVect[k] += eval.getRecallOrientedSimilarity(); } writer.print("</td>"); } } else { for (int i = 0; i < fsize; i++) writer.print("<td>n/a</td>"); } } writer.println("</tr>"); } writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>"); int k = 0; for (String m : listAlgo) { if (foundVect[k] != -1) { for (int i = 0; i < fsize; i++) { writer.print("<td>"); if (format.charAt(i) == 's') { formatter.format("%1.2f", symVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", symVect[k] / expected); } else if (format.charAt(i) == 'e') { formatter.format("%1.2f", effVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", effVect[k] / expected); } else if (format.charAt(i) == 'p') { formatter.format("%1.2f", precOrVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", precOrVect[k] / expected); } else if (format.charAt(i) == 'r') { formatter.format("%1.2f", recOrVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", recOrVect[k] / expected); } writer.println("</td>"); } } else { writer.println("<td colspan='2'><center>Error</center></td>"); } //}; k++; } writer.println("</tr>"); writer.println("</tbody></table>"); writer.println("<p><small>n/a: result alignment not provided or not readable<br />"); writer.println("NaN: division per zero, likely due to empty alignent.</small></p>"); writer.println("</body></html>"); } catch (Exception ex) { logger.debug("IGNORED Exception", ex); } finally { writer.flush(); writer.close(); } }
From source file:no.met.jtimeseries.chart.XYHybridSplineRenderer.java
/** * Add cardinal spline control points in points vector * @param points The points vector/*from w ww .j av a2 s.com*/ * @param tension The tension value to construct cardinal spline * @return Cardinal spline control points */ private Vector<ControlPoint> addCardinalSplinePoints(Vector<ControlPoint> points, float tension) { Vector<ControlPoint> cardinalPoints = new Vector<ControlPoint>(); // construct spline // set the minimum resolution int minimumN = 1; // set the maximum resolution int maximumN = 4; // add two more points at the top and the end for drawing the curve // between the first two and last two points points.add(0, points.get(0)); points.add(points.get(points.size() - 1)); // set the minimum distance when using minimumN double smallDistance = Math.pow( Math.pow(points.get(3).x - points.get(0).x, 2) + Math.pow(points.get(3).y - points.get(0).y, 2), 0.5); double currentDistance; // number of intervals (i.e. parametric curve would be // evaluted currentN times) double currentN; List<ControlPoint> newPoints; for (int i = 0; i < points.size() - 3; i++) { currentDistance = Math.pow(Math.pow(points.get(i + 3).x - points.get(i).x, 2) + Math.pow(points.get(i + 3).y - points.get(i).y, 2), 0.5); currentN = minimumN * currentDistance / smallDistance; currentN = currentN > maximumN ? maximumN : currentN; newPoints = evaluateCardinal2DAtNplusOneValues(points.get(i), points.get(i + 1), points.get(i + 2), points.get(i + 3), tension, (int) currentN); for (int j = 0; j < newPoints.size(); j++) { if (!cardinalPoints.contains(newPoints.get(j))) cardinalPoints.add(new ControlPoint(newPoints.get(j).x, newPoints.get(j).y)); } } // change a small value of the last point in points and add it to control points // for the purpose of spline the line between last two points cardinalPoints.add( new ControlPoint(points.get(points.size() - 1).x + 0.01f, points.get(points.size() - 1).y + 0.01f)); return cardinalPoints; }
From source file:eu.planets_project.tb.impl.model.BasicPropertiesImpl.java
public List<String[]> getAllLiteratureReferences() { //return this.vLiteratureReference; Vector<String[]> vRet = new Vector<String[]>(); Iterator<String> itKeys = this.hmLiteratureReference.keySet().iterator(); while (itKeys.hasNext()) { Vector<String> item = this.hmLiteratureReference.get(itKeys.next()); String[] sRet;//from w w w .j av a 2 s .co m if (item.size() > 2) { sRet = new String[] { item.get(0), item.get(1), item.get(2), item.get(3) }; } else { sRet = new String[] { item.get(0), item.get(1), "", "" }; } vRet.add(sRet); } return vRet; }
From source file:net.sf.javaml.clustering.AQBC.java
/** * Comparable to dist_misval/*from w w w .j a v a2 s . c om*/ * * Calculates the distance between each instance and the instance given as a * float array. * * @param as * @param ck * @return */ private double[] calculateDistances(Vector<TaggedInstance> as, double[] ck) { // voor elke instance van AS, trek er CK van af // return de sqrt van de som de kwadraten van de attributen van het // verschil double[] out = new double[as.size()]; for (int i = 0; i < as.size(); i++) { Double[] values = as.get(i).inst.values().toArray(new Double[0]); // float[]dif=new float[values.length]; float sum = 0; for (int j = 0; j < values.length; j++) { // dif[j]= double dif = values[j] - ck[j]; sum += dif * dif; } out[i] = Math.sqrt(sum); } // Instance tmp=new SimpleInstance(ck); // float[]out=new float[as.size()]; // for(int i=0;i<as.size();i++){ // out[i]=(float)dm.calculateDistance(tmp,as.get(i)); // } return out; }
From source file:eionet.meta.exports.rdf.VoIDXmlWriter.java
/** * Writes data element's VoID xml./*from w w w . j a va 2s.co m*/ * * @param dataElements * @throws XMLStreamException */ public void writeVoIDXml(List<DataElement> dataElements, Vector tables) throws XMLStreamException { String dataElementsBaseUri = Props.getRequiredProperty(PropsIF.RDF_DATAELEMENTS_BASE_URI); String tablesBaseUri = Props.getRequiredProperty(PropsIF.RDF_TABLES_BASE_URI); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); writer.writeStartDocument(ENCODING, "1.0"); writer.writeStartElement(RDF_NS_PREFIX, ROOT_ELEMENT, RDF_NS); writer.writeNamespace(RDF_NS_PREFIX, RDF_NS); writer.writeNamespace(RDFS_NS_PREFIX, RDFS_NS); writer.writeNamespace(OWL_NS_PREFIX, OWL_NS); writer.writeNamespace(DCT_NS_PREFIX, DCT_NS); writer.writeNamespace(VOID_NS_PREFIX, VOID_NS); for (int i = 0; tables != null && i < tables.size(); i++) { DsTable table = (DsTable) tables.get(i); String tableId = table.getID(); String tableRdfUrl = MessageFormat.format(tablesBaseUri, Integer.parseInt(tableId)); writer.writeStartElement(VOID_NS_PREFIX, "Dataset", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "ID", "TBL" + tableId); writer.writeStartElement(RDFS_NS_PREFIX, "label", RDFS_NS); writer.writeCharacters(table.getName()); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "dataDump", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", tableRdfUrl); writer.writeEndElement(); if (StringUtils.isNotEmpty(table.getDstDate())) { Long milliseconds = Long.parseLong(table.getDstDate()); writer.writeStartElement(DCT_NS_PREFIX, "modified", DCT_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "datatype", "http://www.w3.org/2001/XMLSchema#dateTime"); writer.writeCharacters(dateFormat.format(new Date(milliseconds))); writer.writeEndElement(); } writer.writeEndElement(); } for (DataElement de : dataElements) { String dataelementUri = MessageFormat.format(dataElementsBaseUri, de.getId()); writer.writeStartElement(VOID_NS_PREFIX, "Dataset", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "about", StringUtils.substringBeforeLast(dataelementUri, "/rdf")); writer.writeStartElement(RDFS_NS_PREFIX, "label", RDFS_NS); writer.writeCharacters(de.getShortName()); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "dataDump", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", dataelementUri); writer.writeEndElement(); if (de.getModified() != null) { writer.writeStartElement(DCT_NS_PREFIX, "modified", DCT_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "datatype", "http://www.w3.org/2001/XMLSchema#dateTime"); writer.writeCharacters(dateFormat.format(de.getModified())); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndDocument(); }
From source file:agentlogfileanalyzer.histogram.AbstractHistogram.java
/** * Returns a panel containing a histogram. The data displayed in the * histogram is given as parameter. Data not inside the given limits is * discarded.//from w ww . j ava 2 s.co m * * @param _histogramData * the data displayed in the histogram * @param _lowerLimit * the lower limit that was entered by the user * @param _upperLimit * the upper limit that was entered by the user * @return a <code>JPanel</code> containing the histogram */ JPanel createHistogram(Vector<Double> _histogramData, double _lowerLimit, double _upperLimit) { // Remove values outside the given limits... Vector<Double> vectorHistogramDataWithinLimits = new Vector<Double>(); for (Iterator<Double> iterator = _histogramData.iterator(); iterator.hasNext();) { double d = ((Double) iterator.next()).doubleValue(); if (valueWithinLimits(d, _lowerLimit, _upperLimit)) { vectorHistogramDataWithinLimits.add(d); } } // Store number of elements shown in histogram... this.numberOfVisibleClassifiers = vectorHistogramDataWithinLimits.size(); // Convert vector to array... double[] arrayHistogramDataWithinLimits = new double[vectorHistogramDataWithinLimits.size()]; for (int i = 0; i < vectorHistogramDataWithinLimits.size(); i++) { double d = vectorHistogramDataWithinLimits.get(i).doubleValue(); arrayHistogramDataWithinLimits[i] = d; } if (arrayHistogramDataWithinLimits.length > 0) { // Create // histogram... HistogramDataset data = new HistogramDataset(); data.addSeries("Suchwert", // key arrayHistogramDataWithinLimits, // data Math.max(100, arrayHistogramDataWithinLimits.length) // #bins ); JFreeChart chart = ChartFactory.createHistogram(description, // title description, // x axis label "frequency", // y axis label data, // data PlotOrientation.VERTICAL, // orientation false, // legend true, // tooltips false // URL ); return new ChartPanel(chart); } else { return createErrorPanel("No data available (within the given limits)."); } }
From source file:jeeves.resources.dbms.Dbms.java
private Element buildResponse(ResultSet rs, Hashtable<String, String> formats) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int colNum = md.getColumnCount(); // --- retrieve name and type of fields Vector<String> vHeaders = new Vector<String>(); Vector<Integer> vTypes = new Vector<Integer>(); for (int i = 0; i < colNum; i++) { vHeaders.add(md.getColumnLabel(i + 1).toLowerCase()); vTypes.add(new Integer(md.getColumnType(i + 1))); }/* w ww . java 2 s . c o m*/ // --- build the jdom tree Element root = new Element(Jeeves.Elem.RESPONSE); while (rs.next()) { Element record = new Element(Jeeves.Elem.RECORD); for (int i = 0; i < colNum; i++) { String name = vHeaders.get(i).toString(); int type = ((Integer) vTypes.get(i)).intValue(); record.addContent(buildElement(rs, i, name, type, formats)); } root.addContent(record); } return root; }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java
/** Update the ExpMonitors to set the securities and construct the info panel. This is called * as each period is initialized */ public void updatePeriodStatus(int sessionId, Vector securities) { Vector monitors = getMonitors(sessionId); if (monitors == null) { log.warn("Cannot update ExpMonitor with new period status for session " + sessionId + " -- that session does not exist!"); return;/*from w w w. j a v a 2 s . c o m*/ } for (int i = 0; i < monitors.size(); i++) { MonitorTransmitter ui = (MonitorTransmitter) monitors.get(i); try { ui.insertPriceChart(securities); ui.constructInfoPeriodPanel(); } catch (MonitorDisconnectedException e) { log.error( "Failed to establish connection with MonitorTransmitter -- disconnecting from failed monitor"); disconnectMonitor(sessionId, ui); } } }