List of usage examples for java.util Vector size
public synchronized int size()
From source file:Main.java
/** * Method getHashMapFromVector./*from ww w. jav a 2 s . c o m*/ * @param vector Vector * @param keyGetter String * @return HashMap * @throws NoSuchMethodException * @throws Exception * @throws IllegalAccessException */ public static HashMap getHashMapFromVector(Vector vector, String keyGetter) throws NoSuchMethodException, Exception, IllegalAccessException { HashMap hashMap = new HashMap(vector.size()); Object vectorElement = null; Object keyObject = null; Method keyGetterMethod = null; Class[] clsParms = new Class[0]; Object[] objParms = new Object[0]; for (int i = 0; i < vector.size(); i++) { vectorElement = vector.elementAt(i); if (vectorElement != null) { keyGetterMethod = vectorElement.getClass().getMethod(keyGetter, clsParms); keyObject = keyGetterMethod.invoke(vectorElement, objParms); } else { keyObject = null; } hashMap.put(keyObject, vectorElement); } return hashMap; }
From source file:Main.java
public static Hashtable<Integer, Vector<Integer>> getNodeMembership(final Vector<Vector<Integer>> CmtyVV) { Hashtable<Integer, Vector<Integer>> NIDComVH = new Hashtable<Integer, Vector<Integer>>(); for (int CID = 0; CID < CmtyVV.size(); CID++) { for (Integer NID : CmtyVV.get(CID)) { if (!NIDComVH.contains(NID)) { Vector<Integer> v = new Vector<Integer>(); v.add(CID);/*from ww w. j av a 2s . c om*/ NIDComVH.put(NID, v); } else { Vector<Integer> v = NIDComVH.get(NID); v.add(CID); NIDComVH.put(NID, v); } } } return NIDComVH; }
From source file:Main.java
/** * dump bipartite community affiliation into a text file with node names * //from w w w .ja v a 2 s. c o m * @param OutFNm * @param CmtyVV * @param NIDNmH */ static void dumpCmtyVV(final String OutFNm, Vector<Vector<Integer>> CmtyVV, Hashtable<Integer, String> NIDNmH) { PrintWriter f; try { f = new PrintWriter(OutFNm); for (int c = 0; c < CmtyVV.size(); c++) { for (int u = 0; u < CmtyVV.get(c).size(); u++) { if (NIDNmH.containsKey(CmtyVV.get(c).get(u))) { f.printf("%s\t", NIDNmH.get(CmtyVV.get(c).get(u))); } else { f.printf("%d\t", (int) CmtyVV.get(c).get(u)); } } f.printf("\n"); } f.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Method getHashtableFromVector.//from www . j ava 2 s .c o m * @param vector Vector * @param keyGetter String * @return Hashtable * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ public static Hashtable getHashtableFromVector(Vector vector, String keyGetter) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Hashtable hashtable = new Hashtable(vector.size()); Object vectorElement = null; Object keyObject = null; Method keyGetterMethod = null; Class[] clsParms = new Class[0]; Object[] objParms = new Object[0]; for (int i = 0; i < vector.size(); i++) { vectorElement = vector.elementAt(i); keyGetterMethod = vectorElement.getClass().getMethod(keyGetter, clsParms); keyObject = keyGetterMethod.invoke(vectorElement, objParms); hashtable.put(keyObject, vectorElement); } return hashtable; }
From source file:Main.java
public static String[] kommaList2Arr(String s, char sep) { if (s == null) { return null; }//from ww w.j a v a 2 s .c o m Vector v; if (s.length() > 0) { v = split(s, sep); } else { v = new Vector(); } String[] aa = new String[v.size()]; for (int ii = 0; ii < v.size(); ii++) { aa[ii] = (String) v.get(ii); } return aa; }
From source file:Main.java
public static int[] kommaList2IntArr(String s, char sep) { if (s == null) { return null; }//from w ww .ja v a 2 s .co m Vector v; if (s.length() > 0) { v = split(s, sep); } else { v = new Vector(); } int[] aa = new int[v.size()]; for (int ii = 0; ii < v.size(); ii++) { aa[ii] = string2int((String) v.get(ii), 0); } return aa; }
From source file:Main.java
public static Vector getSubSection(Vector a_vecInput, int a_iFromIndex, int a_iToIndex) /* */ {// w ww . java 2s .co m /* 169 */Vector vecReturn = new Vector(); /* 170 */for (int i = 0; i < a_iToIndex; i++) /* */ { /* 172 */if (i >= a_vecInput.size()) /* */ { /* */break; /* */} /* */ /* 177 */if (i < a_iFromIndex) /* */continue; /* 179 */vecReturn.add(a_vecInput.elementAt(i)); /* */} /* */ /* 182 */return vecReturn; /* */}
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 {//ww w . j a v a 2s. co 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:Stats.java
/** * Converts a vector of Numbers into an array of double. This function does * not necessarily belong here, but is commonly required in order to apply * the statistical functions conveniently, since they only deal with arrays * of double. (Note that a Number of the common superclass of all the Object * versions of the primitives, such as Integer, Double etc.). *///from w w w .java2 s . co m // package that at present just provides average and sd of a // vector of doubles // also enables writing the // Gnuplot comments begin with # // next need to find out how to select a particular line style // found it : // This plots sin(x) and cos(x) with linespoints, using the same line type // but different point types: // plot sin(x) with linesp lt 1 pt 3, cos(x) with linesp lt 1 pt 4 public static double[] v2a(Vector v) { double[] d = new double[v.size()]; int i = 0; for (Enumeration e = v.elements(); e.hasMoreElements();) d[i++] = ((Number) e.nextElement()).doubleValue(); return d; }
From source file:Main.java
private static String getXPathFromVector(Vector path) { StringBuffer strBuf = new StringBuffer(); int length = path.size(); for (int i = 0; i < length; i++) { Node tempNode = (Node) path.elementAt(i); short nodeType = getNodeType(tempNode); String targetValue = getValue(tempNode, nodeType); int position = 1; tempNode = getPreviousTypedNode(tempNode, nodeType); while (tempNode != null) { if (nodeType == Node.ELEMENT_NODE) { if (getValue(tempNode, nodeType).equals(targetValue)) { position++;//from w w w . j a v a 2 s . c o m } } else { position++; } tempNode = getPreviousTypedNode(tempNode, nodeType); } boolean hasMatchingSiblings = (position > 1); if (!hasMatchingSiblings) { tempNode = (Node) path.elementAt(i); tempNode = getNextTypedNode(tempNode, nodeType); while (!hasMatchingSiblings && tempNode != null) { if (nodeType == Node.ELEMENT_NODE) { if (getValue(tempNode, nodeType).equals(targetValue)) { hasMatchingSiblings = true; } else { tempNode = getNextTypedNode(tempNode, nodeType); } } else { hasMatchingSiblings = true; } } } String step; switch (nodeType) { case Node.TEXT_NODE: step = "text()"; break; case Node.PROCESSING_INSTRUCTION_NODE: step = "processing-instruction()"; break; default: step = targetValue; break; } if (step != null && step.length() > 0) { strBuf.append('/' + step); } if (hasMatchingSiblings) { strBuf.append("[" + position + "]"); } } return strBuf.toString(); }