List of usage examples for java.util Vector Vector
public Vector()
From source file:Main.java
public static String[] split(final String s, final char c, final boolean dblquotes, final int max) { int j = 0;/*w w w . ja v a2 s .co m*/ final Vector<String> vector = new Vector<String>(); // add first max-1 components int num = 0; int i = 0; String ss = null; int k1; int k2; for (i = 0; num != max - 1; i = j + 1) { k1 = -1; k2 = -1; j = s.indexOf(c, i); if (dblquotes) { // should have k1=0 k1 = s.indexOf('"', i); // quote found and before delimiter if (k1 >= 0 && k1 < j) { // next quote k2 = s.indexOf('"', k1 + 1); if (k2 >= 0) { // recompute next delimiter - should have j=k2+1 j = s.indexOf(c, k2 + 1); } } } if (j >= 0) { if (dblquotes && k1 >= 0 && k2 >= 0) { ss = s.substring(k1 + 1, k2); } else { ss = s.substring(i, j); } vector.addElement(ss); num++; } else { if (dblquotes && k1 >= 0 && k2 >= 0) { ss = s.substring(k1 + 1, k2); } else { ss = s.substring(i); } vector.addElement(ss); num++; break; } } // add the max-th component k1 = -1; k2 = -1; if (max != 0 && j >= 0) { if (dblquotes) { k1 = s.indexOf('"', i); // quote found and before delimiter if (k1 >= 0) { // next quote k2 = s.indexOf('"', k1 + 1); } } if (dblquotes && k1 >= 0 && k2 >= 0) { ss = s.substring(k1 + 1, k2); } else { ss = s.substring(i); } vector.addElement(ss); num++; } // convert to array final String as[] = new String[num]; vector.copyInto(as); // return the array return as; }
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;// ww w.jav a 2 s. c om 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:Main.java
public static Vector<String> getHandsets(String file) throws Exception { Vector<String> vec = new Vector(); DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); DocumentBuilder dombuilder = domfac.newDocumentBuilder(); FileInputStream is = new FileInputStream(file); Document doc = dombuilder.parse(is); NodeList nodeList = doc.getElementsByTagName("devices"); if (nodeList != null && nodeList.getLength() >= 1) { Node deviceNode = nodeList.item(0); NodeList children = deviceNode.getChildNodes(); if (children != null && children.getLength() >= 1) { for (int i = 0; i < children.getLength(); i++) { vec.add(children.item(i).getTextContent()); }/*from w ww . j av a2s. co m*/ } } return vec; }
From source file:Main.java
/** * Returns string keys in a hashtable as array of string * * @param ht// w w w .j a va 2 s .c om * , Hashtable * @return , string array with hash keys string */ public static synchronized String[] hashtableKeysToArray(Hashtable ht) { Vector v = new Vector(); String[] sa = null; int count = 0; Enumeration e = ht.keys(); while (e.hasMoreElements()) { String s = (String) e.nextElement(); v.addElement(s); count++; } sa = new String[count]; v.copyInto(sa); return sa; }
From source file:Main.java
public static Vector<Node> findNodes(String xpath, Node scope) throws XPathExpressionException { XPathFactory xpf = XPathFactory.newInstance(); XPath xp = xpf.newXPath();/*from w w w.ja va2s . c om*/ NodeList nl; Vector<Node> elements = new Vector<Node>(); nl = (NodeList) xp.evaluate(xpath, scope, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) elements.add(nl.item(i)); return elements; }
From source file:Main.java
/** * return the Vector of child Elements with given local name * @param el/*from ww w .java2 s .com*/ * @param name * @return */ public static Vector<Element> namedChildElements(Element el, String lName) { Vector<Element> nc = new Vector<Element>(); for (Iterator<Element> it = childElements(el).iterator(); it.hasNext();) { Element en = it.next(); if (getLocalName(en).equals(lName)) nc.addElement(en); } return nc; }
From source file:Main.java
public static Vector<Element> findElements(String xpath, Node scope) throws XPathExpressionException { XPathFactory xpf = XPathFactory.newInstance(); XPath xp = xpf.newXPath();//from w w w. j a va2s . c om NodeList nl; Vector<Element> elements = new Vector<Element>(); nl = (NodeList) xp.evaluate(xpath, scope, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) elements.add((Element) nl.item(i)); return elements; }
From source file:Main.java
public static Vector<HashMap> xmltoVector222(String xmlFile, String xpath) { try {/* ww w. j av a 2 s.co m*/ if (!new File(xmlFile).exists()) { return new Vector<HashMap>(); } File xmlDocument = new File(xmlFile); InputSource inputSource = new InputSource(); return xmlToVector222(new FileInputStream(xmlDocument), xpath); } catch (Exception ex) { ex.printStackTrace(); return new Vector<HashMap>(); } }
From source file:Main.java
public static Document removeFromRootElement(Document document, String nodeName, String attributeName, String attributeValue) {//from w ww . j a v a2s . co m try { Element rootElement = document.getDocumentElement(); NodeList nl = document.getElementsByTagName(nodeName); Vector<Node> deletedNodes = new Vector<Node>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); String noteAttributeValue = node.getAttributes().getNamedItem(attributeName).getNodeValue(); if (noteAttributeValue.equals(attributeValue)) { deletedNodes.add(node); } } for (Node deletedNode : deletedNodes) { rootElement.removeChild(deletedNode); } } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:Main.java
/** * Extract included filenames in the XML document, assuming that filenames are * provided with the attribute "href".//from w ww. j av a2 s . co m * * @param xmlDocument the XML document * @return the filenames to include */ private static Vector<String> extractIncludedFiles(Document xmlDocument) { Vector<String> includedFiles = new Vector<String>(); NodeList top = xmlDocument.getChildNodes(); for (int i = 0; i < top.getLength(); i++) { Node topNode = top.item(i); NodeList firstElements = topNode.getChildNodes(); for (int j = 0; j < firstElements.getLength(); j++) { Node midNode = firstElements.item(j); for (int k = 0; k < midNode.getChildNodes().getLength(); k++) { Node node = midNode.getChildNodes().item(k); if (node.hasAttributes() && node.getAttributes().getNamedItem("href") != null) { String fileName = node.getAttributes().getNamedItem("href").getNodeValue(); includedFiles.add(fileName); } } } } return includedFiles; }