List of usage examples for java.util Vector removeAllElements
public synchronized void removeAllElements()
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("1");//from w w w. j a v a 2 s. c o m v.add("2"); v.add("3"); System.out.println(v.size()); v.clear(); v.removeAllElements(); System.out.println(v.size()); }
From source file:Main.java
public static void main(String[] args) { Vector vec = new Vector(4); vec.add(4);// w w w . j a va 2 s . c o m vec.add(3); vec.add(2); vec.add(1); System.out.println(vec); System.out.println("Size of the vector: " + vec.size()); System.out.println("Removing all elements"); // lets remove all the elements vec.removeAllElements(); System.out.println("Now size of the vector: " + vec.size()); }
From source file:org.uma.jmetal.util.experiment.component.GenerateFriedmanTestTables.java
private double[] computeAverageRanking(Vector<Vector<Double>> data) { /*Compute the average performance per algorithm for each data set*/ double[][] mean = new double[numberOfProblems][numberOfAlgorithms]; for (int j = 0; j < numberOfAlgorithms; j++) { for (int i = 0; i < numberOfProblems; i++) { mean[i][j] = data.elementAt(j).elementAt(i); }//from w w w. j ava2 s .co m } /*We use the Pair class to compute and order rankings*/ List<List<Pair<Integer, Double>>> order = new ArrayList<List<Pair<Integer, Double>>>(numberOfProblems); for (int i = 0; i < numberOfProblems; i++) { order.add(new ArrayList<Pair<Integer, Double>>(numberOfAlgorithms)); for (int j = 0; j < numberOfAlgorithms; j++) { order.get(i).add(new ImmutablePair<Integer, Double>(j, mean[i][j])); } Collections.sort(order.get(i), new Comparator<Pair<Integer, Double>>() { @Override public int compare(Pair<Integer, Double> pair1, Pair<Integer, Double> pair2) { if (Math.abs(pair1.getValue()) > Math.abs(pair2.getValue())) { return 1; } else if (Math.abs(pair1.getValue()) < Math.abs(pair2.getValue())) { return -1; } else { return 0; } } }); } /*building of the rankings table per algorithms and data sets*/ // Pair[][] rank = new Pair[numberOfProblems][numberOfAlgorithms]; List<List<MutablePair<Double, Double>>> rank = new ArrayList<List<MutablePair<Double, Double>>>( numberOfProblems); int position = 0; for (int i = 0; i < numberOfProblems; i++) { rank.add(new ArrayList<MutablePair<Double, Double>>(numberOfAlgorithms)); for (int j = 0; j < numberOfAlgorithms; j++) { boolean found = false; for (int k = 0; k < numberOfAlgorithms && !found; k++) { if (order.get(i).get(k).getKey() == j) { found = true; position = k + 1; } } //rank[i][j] = new Pair(position,order[i][position-1].value); rank.get(i).add(new MutablePair<Double, Double>((double) position, order.get(i).get(position - 1).getValue())); } } /*In the case of having the same performance, the rankings are equal*/ for (int i = 0; i < numberOfProblems; i++) { boolean[] hasBeenVisited = new boolean[numberOfAlgorithms]; Vector<Integer> pendingToVisit = new Vector<Integer>(); Arrays.fill(hasBeenVisited, false); for (int j = 0; j < numberOfAlgorithms; j++) { pendingToVisit.removeAllElements(); double sum = rank.get(i).get(j).getKey(); hasBeenVisited[j] = true; int ig = 1; for (int k = j + 1; k < numberOfAlgorithms; k++) { if (rank.get(i).get(j).getValue() == rank.get(i).get(k).getValue() && !hasBeenVisited[k]) { sum += rank.get(i).get(k).getKey(); ig++; pendingToVisit.add(k); hasBeenVisited[k] = true; } } sum /= (double) ig; rank.get(i).get(j).setLeft(sum); for (int k = 0; k < pendingToVisit.size(); k++) { rank.get(i).get(pendingToVisit.elementAt(k)).setLeft(sum); } } } /*compute the average ranking for each algorithm*/ double[] averageRanking = new double[numberOfAlgorithms]; for (int i = 0; i < numberOfAlgorithms; i++) { averageRanking[i] = 0; for (int j = 0; j < numberOfProblems; j++) { averageRanking[i] += rank.get(j).get(i).getKey() / ((double) numberOfProblems); } } return averageRanking; }
From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java
@SuppressWarnings("UseOfObsoleteCollectionType") public final void updateView() { if (data == null) { return;/*w w w . j av a2 s .c o m*/ } boolean first = false; if (model == null) { model = new GenericTableModel(data, columnNames, columnClasses); first = true; } else { java.util.Vector dataVec = model.getDataVector(); dataVec.removeAllElements(); int rowIndex = 0; keyRowIndexMap = new HashMap<Object, Set<Integer>>(); for (Object[] row : data) { if (row == null) { System.out.println("Got null row!"); } dataVec.add(new java.util.Vector(Arrays.asList(row))); addToRowIndexMap(getKey(row), rowIndex++); } } if (first) { int[] columns = new int[columnNames.length]; for (int i = 0; i < columns.length; i++) { columns[i] = i; } filterField.setTableModel(model); filterField.setColumnIndices(columns); filterField.setObjectConverterManagerEnabled(true); table.setModel(new FilterableTableModel(filterField.getDisplayTableModel())); columnChooser.hideColumns(hiddenColumns); int[] favColumns = new int[columnNames.length - hiddenColumns.length]; int pos = 0; for (int i = 0; i < columnNames.length; i++) { boolean hidden = false; for (int j = 0; j < hiddenColumns.length; j++) { if (hiddenColumns[j] == i) { hidden = true; break; } } if (!hidden) { favColumns[pos] = i; pos++; } } columnChooser.setFavoriteColumns(favColumns); } else { model.fireTableDataChanged(); } }
From source file:rss.RSSController.java
public void parseElement(java.util.Vector<channel> tabChannels, javax.swing.DefaultListModel names) { if (_inputs.size() > 0) { String input = _inputs.get(0); JSONParser parser = new JSONParser(); String jsonText = input;//w w w. ja v a 2 s. c o m try { JSONArray array = (JSONArray) parser.parse(jsonText); tabChannels.removeAllElements(); for (int i = 0; i < array.size(); ++i) { channel c = new channel(); JSONObject obj = (JSONObject) array.get(i); Object[] tab = obj.values().toArray(); System.out.println(tab); JSONArray arr = (JSONArray) obj.get("items"); c.setName((String) obj.get("title")); for (int j = 0; j < arr.size(); ++j) { JSONObject o = (JSONObject) arr.get(j); c.push((String) o.get("description")); } tabChannels.addElement(c); names.addElement((String) tab[3]); // return (c); } } catch (ParseException pe) { } } else { } }
From source file:org.openbravo.erpCommon.ad_reports.MInOutTraceReports.java
private String processChilds(VariablesSecureApp vars, String mAttributesetinstanceId, String mProductId, String mLocatorId, String strIn, boolean colorbg2, String strmProductIdGlobal, Hashtable<String, Integer> calculated, Vector<Integer> count) throws ServletException { BigDecimal total = BigDecimal.ZERO; BigDecimal totalPedido = BigDecimal.ZERO; StringBuffer strHtml = new StringBuffer(); String strCalculated = mProductId + "&" + mAttributesetinstanceId + "&" + mLocatorId; int c = count.get(0).intValue(); c += 1;/*from w w w .ja v a 2 s. c o m*/ count.removeAllElements(); count.add(new Integer(c)); calculated.put(strCalculated, new Integer(c)); if (log4j.isDebugEnabled()) log4j.debug("****** Hashtable.add: " + strCalculated); MInOutTraceReportsData[] dataChild = MInOutTraceReportsData.selectChilds(this, vars.getLanguage(), mAttributesetinstanceId, mProductId, mLocatorId, strIn.equals("Y") ? "plusQty" : "minusQty", strIn.equals("N") ? "minusQty" : "plusQty"); if (dataChild == null || dataChild.length == 0) { return ""; } boolean colorbg = true; strHtml.append(insertHeaderHtml(false, "0")); for (int i = 0; i < dataChild.length; i++) { strHtml.append("<tr style=\"background: ").append((colorbg ? "#CFDDE8" : "#FFFFFF")).append("\">"); colorbg = !colorbg; strHtml.append("<td >\n"); strHtml.append(getData(dataChild[i], "")); strHtml.append("</td>"); total = total.add(new BigDecimal(dataChild[i].movementqty)); if (!dataChild[i].quantityorder.equals("")) totalPedido = totalPedido.add(new BigDecimal(dataChild[i].quantityorder)); strHtml.append(insertTotal(total.toPlainString(), dataChild[i].uomName, totalPedido.toPlainString(), dataChild[i].productUomName)); strHtml.append(" </tr>\n"); if (log4j.isDebugEnabled()) log4j.debug("****** New line, qty: " + dataChild[i].movementqty + " " + getData(dataChild[i], "TraceSubTable")); strHtml.append(processExternalChilds(vars, dataChild[i], strIn, colorbg2, strmProductIdGlobal, calculated, count)); } strHtml.append(insertHeaderHtml(true, "")); return strHtml.toString(); }
From source file:org.ut.biolab.medsavant.client.view.component.SearchableTablePanel.java
/** * Brute-force replacement of current table data with the given data, * blowing away the current table selection. * * @param pageData the new data//www .j ava 2 s .c om */ @SuppressWarnings("UseOfObsoleteCollectionType") public synchronized void applyData(List<Object[]> pageData) { if (pageData != null) { // We can't call setDataVector directly because that blows away any custom table renderers we've set. java.util.Vector v = model.getDataVector(); v.removeAllElements(); for (Object[] r : pageData) { v.add(new java.util.Vector(Arrays.asList(r))); } } gotoFirst.setEnabled(true); gotoPrevious.setEnabled(true); gotoNext.setEnabled(true); gotoLast.setEnabled(true); if (pageNum == 1 || pageNum == 0) { gotoFirst.setEnabled(false); gotoPrevious.setEnabled(false); } if (pageNum == getTotalNumPages() || pageNum == 0) { gotoNext.setEnabled(false); gotoLast.setEnabled(false); } pageText.setText(Integer.toString(getPageNumber())); pageLabel2.setText(" of " + ViewUtil.numToString(getTotalNumPages())); int start = getTotalNumPages() == 0 ? 0 : (getPageNumber() - 1) * getRowsPerPage() + 1; int end = getTotalNumPages() == 0 ? 0 : Math.min(start + getRowsPerPage() - 1, getTotalRowCount()); amountLabel.setText(" Showing " + ViewUtil.numToString(start) + " - " + ViewUtil.numToString(end) + " of " + ViewUtil.numToString(getTotalRowCount())); model.fireTableDataChanged(); }
From source file:org.kepler.kar.KARBuilder.java
public void generateKAR(TableauFrame tableauFrame, String overrideModDeps) throws IllegalActionException { if (isDebugging) log.debug("generateKAR()"); if (_karLSID == null) { try {/* w w w . j a va 2 s.c om*/ _karLSID = LSIDGenerator.getInstance().getNewLSID(); } catch (Exception e) { log.error("could not generate new LSID for KAR: " + e.getMessage()); e.printStackTrace(); } } try { // Get KAREntries for the Save Initiator List Hashtable<KAREntry, InputStream> initiatorEntries = handleInitiatorList(); addEntriesToPrivateItems(initiatorEntries); int pass = 1; // Loop through KAR Entry handlers until no more KAREntry objects // are returned Vector<KeplerLSID> previousPassEntryLSIDs = getKAREntryLSIDs(initiatorEntries); if (isDebugging) log.debug("Pass " + pass + " entries: " + previousPassEntryLSIDs.toString()); while (previousPassEntryLSIDs.size() > 0) { pass++; // Get the KAREntries from all of the handlers Hashtable<KAREntry, InputStream> entries = queryKAREntryHandlers(previousPassEntryLSIDs, tableauFrame); if (entries != null) { previousPassEntryLSIDs.removeAllElements(); if (isDebugging) log.debug("Pass " + pass + " entries: "); Vector<KeplerLSID> repeats = new Vector<KeplerLSID>(); for (KAREntry karEntryKey : entries.keySet()) { String entryName = karEntryKey.getName(); String entryType = karEntryKey.getType(); KeplerLSID entryLSID = karEntryKey.getLSID(); if (isDebugging) log.debug(entryName + " " + entryLSID + " " + entryType); if (_karItemLSIDs.contains(entryLSID)) { // TODO make sure existing Entry Handlers do not produce repeated LSIDs. // This should never happen. System.out.println("KARBuilder generateKAR() Trying to add " + entryName + " with " + "type:" + entryType + " but an entry with lsid:" + entryLSID + " has already " + "been added to KAR. Will NOT add this entry."); repeats.add(entryLSID); } else if (_karItemNames.contains(entryName)) { // TODO make sure existing Entry Handlers do not produce repeated LSIDs. // This should never happen. System.out.println("KARBuilder generateKAR() An entry with entryName" + entryName + " has already been added to KAR. Will NOT add this entry with lsid:" + entryLSID); repeats.add(entryLSID); } else { previousPassEntryLSIDs.add(entryLSID); } } // A kludge to protect against entry handlers returning entries that have already been added for (KeplerLSID repeatedLSID : repeats) { for (KAREntry ke : entries.keySet()) { if (ke.getLSID().equals(repeatedLSID)) { entries.remove(ke); if (isDebugging) log.debug("Removed " + repeatedLSID + " from pass " + pass + " entries"); break; } } } addEntriesToPrivateItems(entries); } } prepareManifest(overrideModDeps); writeKARFile(); } catch (Exception e) { throw new IllegalActionException("Error building the KAR file: " + e.getMessage()); } }
From source file:org.jfree.chart.demo.JFreeChartDemo.java
/** * Creates a tabbed pane containing descriptions of the demo charts. * * @param resources localised resources. * * @return a tabbed pane.//from w w w . j a v a 2s .c om */ private JTabbedPane createTabbedPane(final ResourceBundle resources) { final Font font = new Font("Dialog", Font.PLAIN, 12); final JTabbedPane tabs = new JTabbedPane(); int tab = 1; final Vector titles = new Vector(0); final String[] tabTitles; String title = null; while (tab > 0) { try { title = resources.getString("tabs." + tab); if (title != null) { titles.add(title); } else { tab = -1; } ++tab; } catch (Exception ex) { tab = -1; } } if (titles.size() == 0) { titles.add("Default"); } tab = titles.size(); this.panels = new JPanel[tab]; tabTitles = new String[tab]; --tab; for (; tab >= 0; --tab) { title = titles.get(tab).toString(); tabTitles[tab] = title; } titles.removeAllElements(); for (int i = 0; i < tabTitles.length; ++i) { this.panels[i] = new JPanel(); this.panels[i].setLayout(new LCBLayout(20)); this.panels[i].setPreferredSize(new Dimension(360, 20)); this.panels[i].setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); tabs.add(tabTitles[i], new JScrollPane(this.panels[i])); } String description; final String buttonText = resources.getString("charts.display"); JButton b1; // Load the CHARTS ... String usage = null; for (int i = 0; i <= CHART_COMMANDS.length - 1; ++i) { try { usage = resources.getString(CHART_COMMANDS[i][2] + ".usage"); } catch (Exception ex) { usage = null; } if ((usage == null) || usage.equalsIgnoreCase("All") || usage.equalsIgnoreCase("Swing")) { title = resources.getString(CHART_COMMANDS[i][2] + ".title"); description = resources.getString(CHART_COMMANDS[i][2] + ".description"); try { tab = Integer.parseInt(resources.getString(CHART_COMMANDS[i][2] + ".tab")); --tab; } catch (Exception ex) { System.err.println("Demo : Error retrieving tab identifier for chart " + CHART_COMMANDS[i][2]); System.err.println("Demo : Error = " + ex.getMessage()); tab = 0; } if ((tab < 0) || (tab >= this.panels.length)) { tab = 0; } System.out.println("Demo : adding " + CHART_COMMANDS[i][0] + " to panel " + tab); this.panels[tab].add(RefineryUtilities.createJLabel(title, font)); this.panels[tab].add(new DescriptionPanel(new JTextArea(description))); b1 = RefineryUtilities.createJButton(buttonText, font); b1.setActionCommand(CHART_COMMANDS[i][0]); b1.addActionListener(this); this.panels[tab].add(b1); } } return tabs; }
From source file:Matrix.java
/** * Read a matrix from a stream. The format is the same the print method, so * printed matrices can be read back in (provided they were printed using US * Locale). Elements are separated by whitespace, all the elements for each * row appear on a single line, the last row is followed by a blank line. * /*from w w w . ja v a2 s. c om*/ * @param input * the input stream. */ public static Matrix read(BufferedReader input) throws java.io.IOException { StreamTokenizer tokenizer = new StreamTokenizer(input); // Although StreamTokenizer will parse numbers, it doesn't recognize // scientific notation (E or D); however, Double.valueOf does. // The strategy here is to disable StreamTokenizer's number parsing. // We'll only get whitespace delimited words, EOL's and EOF's. // These words should all be numbers, for Double.valueOf to parse. tokenizer.resetSyntax(); tokenizer.wordChars(0, 255); tokenizer.whitespaceChars(0, ' '); tokenizer.eolIsSignificant(true); java.util.Vector v = new java.util.Vector(); // Ignore initial empty lines while (tokenizer.nextToken() == StreamTokenizer.TT_EOL) ; if (tokenizer.ttype == StreamTokenizer.TT_EOF) throw new java.io.IOException("Unexpected EOF on matrix read."); do { v.addElement(Double.valueOf(tokenizer.sval)); // Read & store 1st // row. } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD); int n = v.size(); // Now we've got the number of columns! double row[] = new double[n]; for (int j = 0; j < n; j++) // extract the elements of the 1st row. row[j] = ((Double) v.elementAt(j)).doubleValue(); v.removeAllElements(); v.addElement(row); // Start storing rows instead of columns. while (tokenizer.nextToken() == StreamTokenizer.TT_WORD) { // While non-empty lines v.addElement(row = new double[n]); int j = 0; do { if (j >= n) throw new java.io.IOException("Row " + v.size() + " is too long."); row[j++] = Double.valueOf(tokenizer.sval).doubleValue(); } while (tokenizer.nextToken() == StreamTokenizer.TT_WORD); if (j < n) throw new java.io.IOException("Row " + v.size() + " is too short."); } int m = v.size(); // Now we've got the number of rows. double[][] A = new double[m][]; v.copyInto(A); // copy the rows out of the vector return new Matrix(A); }