List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:Main.java
public static void writeContatctInfo(String accountId, Vector contactInfo, File contactInfoFile) throws IOException { contactInfoFile.getParentFile().mkdirs(); FileOutputStream contactFileOutputStream = new FileOutputStream(contactInfoFile); DataOutputStream out = new DataOutputStream(contactFileOutputStream); out.writeUTF((String) contactInfo.get(0)); out.writeInt(((Integer) (contactInfo.get(1))).intValue()); for (int i = 2; i < contactInfo.size(); ++i) { out.writeUTF((String) contactInfo.get(i)); }/* www . j a va 2 s .c o m*/ out.close(); }
From source file:eu.amidst.core.utils.Utils.java
/** * Returns the sumNonStateless of the elements in a given vector. * @param vector a {@link Vector} object. * @return a {@code double} that represents the sumNonStateless of the vector elements. */// w ww. j a va 2 s .c o m public static double sum(Vector vector) { double sum = 0; for (int i = 0; i < vector.size(); i++) { sum += vector.get(i); } return sum; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.HierarchicalBarChart.java
@SuppressWarnings("unchecked") private static Comparable[] toSeries(Vector<Counter> counter) { Comparable[] result = new Comparable[counter.size()]; for (int i = 0; i < counter.size(); i++) { result[i] = ((Counter) counter.get(i)).getName(); }/* w w w . ja v a 2s . com*/ return result; }
From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParser.java
private static String splitAndPad(final String s, final int totalWidth, final int targetWidth) { Vector<String> lines = splitIntoLines(s, targetWidth); if (lines.size() == 0) { return ""; } else {//from w w w . j a va 2 s .c o m String prefix = ofChars(' ', totalWidth - targetWidth); String ret = lines.get(0) + "\n"; for (int i = 1; i < lines.size(); i++) { ret += prefix; ret += lines.get(i); ret += "\n"; } return ret; } }
From source file:Main.java
public static Vector<Integer> mergeSet(Vector<Integer> leftSet, Vector<Integer> rightSet, String mergeType) { if (leftSet == null || rightSet == null) return null; if (mergeType.trim().compareToIgnoreCase("or") == 0) { // OR set Vector<Integer> orSet = new Vector<Integer>(); orSet = leftSet;/* w ww. j a v a2 s .co m*/ for (int i = 0; i < rightSet.size(); i++) { if (orSet.contains(rightSet.get(i)) == false) orSet.add(rightSet.get(i)); } return orSet; } else if (mergeType.trim().compareToIgnoreCase("and") == 0) { // AND // set Vector<Integer> andSet = new Vector<Integer>(); if (leftSet.size() > rightSet.size()) { for (int i = 0; i < rightSet.size(); i++) { if (leftSet.contains(rightSet.get(i)) == true) andSet.add(rightSet.get(i)); } } else { for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == true) andSet.add(leftSet.get(i)); } } return andSet; } else if (mergeType.trim().compareToIgnoreCase("xor") == 0) { // XoR // set // Left is Universal Set and right Set is getting Exclusive XoR Vector<Integer> xorSet = new Vector<Integer>(); for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == false) xorSet.add(leftSet.get(i)); } return xorSet; } return leftSet; }
From source file:eu.amidst.core.utils.Utils.java
/** * Returns the index of the maximum element in a given vector. * @param vector a {@link Vector} object. * @return an {@code int} that represents the index of the maximum element in the vector. *///from ww w. j a v a2s . co m public static int maxIndex(Vector vector) { double max = Double.NEGATIVE_INFINITY; int index = -1; for (int i = 0; i < vector.size(); i++) { if (vector.get(i) > max) { max = vector.get(i); index = i; } } if (index == -1) throw new IllegalStateException("There is no maximum. Probably a NaN value."); return index; }
From source file:eu.amidst.core.utils.Utils.java
/** * Returns the index of the minimum element in a given vector. * @param vector a {@link Vector} object. * @return an {@code int} that represents the index of the minimum element in the vector. *//*from w ww. j a v a 2 s. c om*/ public static int minIndex(Vector vector) { double min = Double.POSITIVE_INFINITY; int index = -1; for (int i = 0; i < vector.size(); i++) { if (vector.get(i) < min) { min = vector.get(i); index = i; } } if (index == -1) throw new IllegalStateException("There is no maximum. Probably a NaN value."); return index; }
From source file:Main.java
public static String getMonthNameShort(Integer pos) { Vector<String> monthsShort = new Vector<String>(); monthsShort.add("Jan"); monthsShort.add("Feb"); monthsShort.add("Mar"); monthsShort.add("Apr"); monthsShort.add("May"); monthsShort.add("Jun"); monthsShort.add("Jul"); monthsShort.add("Aug"); monthsShort.add("Sep"); monthsShort.add("Oct"); monthsShort.add("Nov"); monthsShort.add("Dec"); return monthsShort.get(pos); }
From source file:eu.cassandra.csn.gui.Stats.java
/** * // w w w.j a va2 s . c om * @param instInfo */ public static void updateTableModelSelected(Vector<InstallationInfo> instInfos) { for (int i = tableModelSelected.getRowCount() - 1; i >= 0; i--) { tableModelSelected.removeRow(i); } for (int i = 0; i < instInfos.size(); i++) { InstallationInfo instInfo = instInfos.get(i); String[] rowData = new String[5]; rowData[0] = (instInfo.getInstallationName() != null ? instInfo.getInstallationName() : ""); rowData[1] = (instInfo.getInstallationType() != null ? instInfo.getInstallationType() : ""); rowData[2] = String.valueOf( (instInfo.getTotalConsumption() != 0.0 ? instInfo.getTotalConsumption() : "")) + " kWh"; rowData[3] = String .valueOf((instInfo.getPeakComsumption() != 0.0 ? instInfo.getPeakComsumption() : "") + " W"); rowData[4] = String .valueOf((instInfo.getAvgConsumption() != 0.0 ? instInfo.getAvgConsumption() : "") + " W"); tableModelSelected.addRow(rowData); } Double[] data; if (instInfos.size() == 1) { String inst_id = instInfos.get(0).getID(); data = MongoQueries.getInstallationResults(inst_id); } else { data = new Double[0]; } XYSeries series1 = new XYSeries("First"); for (int i = 0; i < data.length / 15; i++) { double d = 0; for (int j = 0; j < 60; j++) { d += data[j * 60 + i]; } series1.add(i, d); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); chartPanel.getChart().getXYPlot().setDataset(dataset); }
From source file:de.innovationgate.wgpublisher.bi.BiBase.java
public static String getBrowserLanguageKey(javax.servlet.jsp.PageContext pageContext) { Enumeration enumLocales = pageContext.getRequest().getLocales(); Vector vecLocales = new Vector(); vecLocales.clear();/*from w w w.jav a 2s . c o m*/ String language = null; while (enumLocales.hasMoreElements()) vecLocales.add((Locale) enumLocales.nextElement()); for (int i = 0; i < vecLocales.size(); i++) { Locale currentLocale = (Locale) vecLocales.get(i); language = currentLocale.getLanguage().toUpperCase(); if (language.equalsIgnoreCase("DE") || language.equalsIgnoreCase("EN")) break; } if (language == null || language.equals("")) language = "EN"; return language; }