List of usage examples for java.util Vector size
public synchronized int size()
From source file:modnlp.capte.AlignerUtils.java
public static void reWriteAlignment(String sourcename, String targetname, Vector<Object[]> d) { try {/* w w w.jav a2 s . c om*/ FileOutputStream op = new FileOutputStream(sourcename); Writer out = new OutputStreamWriter(op, "UTF-8"); FileOutputStream sp = new FileOutputStream(targetname); Writer sout = new OutputStreamWriter(sp, "UTF-8"); String source = ""; String target = ""; Object[] stemp; for (int i = 0; i < d.size(); i++) { stemp = d.get(i); source = (String) stemp[0]; target = (String) stemp[1]; source = clean(source); target = clean(target); out.write(source); out.write("\n"); sout.write(target); sout.write("\n"); System.out.println(source); System.out.println(target); } out.close(); sout.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Method getLimit./*www.j a v a 2 s . c om*/ * @param vector Vector * @param getter String * @param limitType int * @return Object * @throws NoSuchMethodException * @throws IllegalAccessException * @throws Exception */ private static Object getLimit(Vector vector, String getter, int limitType) throws NoSuchMethodException, IllegalAccessException, Exception { Object limitObject = null; Object currentObject = null; Method getterMethod = null; Method compareMethod = null; Object vectorElement = null; Class[] clsParms = new Class[0]; Object[] objParms = new Object[0]; Class[] objectClass = new Class[1]; Object[] limitObjectArray = new Object[1]; int compareResult = 0; try { objectClass[0] = Class.forName("java.lang.Object"); } catch (Exception e) { } if (vector.size() > 0) { vectorElement = vector.elementAt(0); getterMethod = vectorElement.getClass().getMethod(getter, clsParms); limitObject = getterMethod.invoke(vectorElement, objParms); if ((limitObject == null) && (limitType == MIN)) { return null; } } for (int i = 1; i < vector.size(); i++) { vectorElement = vector.elementAt(i); if (vectorElement != null) { getterMethod = vectorElement.getClass().getMethod(getter, clsParms); currentObject = getterMethod.invoke(vectorElement, objParms); } else { currentObject = null; } if (currentObject != null) { if (limitObject != null) { compareMethod = currentObject.getClass().getMethod("compareTo", objectClass); limitObjectArray[0] = limitObject; compareResult = ((Integer) compareMethod.invoke(currentObject, limitObjectArray)).intValue(); } else { compareResult = 1; } } else { if (limitObject != null) { compareResult = -1; } else { compareResult = 0; } } if (((compareResult > 0) && (limitType == MAX)) || ((compareResult < 0) && (limitType == MIN))) { limitObject = currentObject; } } return limitObject; }
From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java
/** * Returns a list of all Species /* ww w . ja va2s . c o m*/ * Used for submission and search screens * * @return speciesNames * @throws Exception */ private static List getQueryOnlySpeciesList(HttpServletRequest inRequest, String inAddBlank) throws Exception { log.debug("Entering NewDropdownUtil.getQueryOnlySpeciesList"); Species sp = new Species(); Vector species = sp.retrieveAllWhere("species_name IS NOT NULL ORDER BY species_name"); // Get values for dropdown lists for Species List<DropdownOption> theReturnList = new ArrayList<DropdownOption>(); for (int j = 0; j < species.size(); j++) { Species speciesTab = (Species) species.elementAt(j); if (speciesTab.getSpecies_id() != null) { DropdownOption theOption = new DropdownOption(speciesTab.getSpecies_name(), speciesTab.getSpecies_id().toString()); theReturnList.add(theOption); } } log.debug("Exiting getQueryOnlySpeciesList.size " + theReturnList.size()); return theReturnList; }
From source file:gov.nih.nci.evs.browser.utils.ViewInHierarchyUtils.java
public static ConceptReferenceList createConceptReferenceList(Vector codes, String codingSchemeName) { if (codes == null) { return null; }//w w w .ja va 2 s . c o m ConceptReferenceList list = new ConceptReferenceList(); for (int i = 0; i < codes.size(); i++) { String code = (String) codes.elementAt(i); ConceptReference cr = new ConceptReference(); cr.setCodingSchemeName(codingSchemeName); cr.setConceptCode(code); list.addConceptReference(cr); } return list; }
From source file:Main.java
/** * Method getLimit./*w ww .ja va 2 s .c o m*/ * @param vector Vector * @param getter String * @param limitType int * @return Object * @throws NoSuchMethodException * @throws IllegalAccessException * @throws InvocationTargetException */ private static Object getLimit(Vector vector, String getter, int limitType) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Object limitObject = null; Object currentObject = null; Method getterMethod = null; Method compareMethod = null; Object vectorElement = null; Class[] clsParms = new Class[0]; Object[] objParms = new Object[0]; Class[] objectClass = new Class[1]; Object[] limitObjectArray = new Object[1]; int compareResult = 0; try { objectClass[0] = Class.forName("java.lang.Object"); } catch (Exception e) { } if (vector.size() > 0) { vectorElement = vector.elementAt(0); getterMethod = vectorElement.getClass().getMethod(getter, clsParms); limitObject = getterMethod.invoke(vectorElement, objParms); if ((limitObject == null) && (limitType == MIN)) { return null; } } for (int i = 1; i < vector.size(); i++) { vectorElement = vector.elementAt(i); if (vectorElement != null) { getterMethod = vectorElement.getClass().getMethod(getter, clsParms); currentObject = getterMethod.invoke(vectorElement, objParms); } else { currentObject = null; } if (currentObject != null) { if (limitObject != null) { compareMethod = currentObject.getClass().getMethod("compareTo", objectClass); limitObjectArray[0] = limitObject; compareResult = ((Integer) compareMethod.invoke(currentObject, limitObjectArray)).intValue(); } else { compareResult = 1; } } else { if (limitObject != null) { compareResult = -1; } else { compareResult = 0; } } if (((compareResult > 0) && (limitType == MAX)) || ((compareResult < 0) && (limitType == MIN))) { limitObject = currentObject; } } return limitObject; }
From source file:Main.java
public static void vectorToXML222(String xmlFile, String xpath, String parentNodeName, Vector<HashMap> vector) { File file = new File(xmlFile); try {/*from w w w .j ava 2s. c om*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document; Element rootNode; if (file.exists()) { document = documentBuilder.parse(new File(xmlFile)); rootNode = document.getDocumentElement(); } else { document = documentBuilder.newDocument(); rootNode = document.createElement(xpath); document.appendChild(rootNode); } for (int x = 0; x < vector.size(); x++) { Element parentNode = document.createElement(parentNodeName); rootNode.appendChild(parentNode); HashMap hashmap = vector.get(x); Set set = hashmap.entrySet(); Iterator i = set.iterator(); while (i.hasNext()) { Map.Entry me = (Map.Entry) i.next(); // System.out.println("key=" + // me.getKey().toString()); Element em = document.createElement(me.getKey().toString()); em.appendChild(document.createTextNode(me.getValue().toString())); parentNode.appendChild(em); // System.out.println("write " + // me.getKey().toString() + // "=" // + me.getValue().toString()); } } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); FileOutputStream fo = new FileOutputStream(xmlFile); StreamResult result = new StreamResult(fo); transformer.transform(source, result); } catch (Exception ex) { file.delete(); ex.printStackTrace(); } }
From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java
private static Object getParameter(int index, Vector<Object> parameters) { if (index > parameters.size() - 1) return null; return parameters.get(index); }
From source file:modnlp.capte.AlignerUtils.java
public static void writeAlignment(String sourcename, Vector<Object[]> d) { //Output the current alignment as a tab separated file String sp = ""; BufferedWriter pw;//from w ww. j a v a2 s . co m try { pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sourcename), "UTF-8")); //PrintWriter tp = new PrintWriter(new OutputStreamWriter(new FileOutputStream(targetname),"UTF8")); String source = ""; String target = ""; Object[] stemp; for (int i = 0; i < d.size(); i++) { stemp = d.get(i); source = (String) stemp[0]; target = (String) stemp[1]; source = clean(source); target = clean(target); sp += source + "\t" + target + "\n"; } pw.write(new String(UnicodeUtil.convert(sp.getBytes(), "UTF-8"))); pw.close(); //return sp; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tethrnet.manage.util.SSHUtil.java
public static List<String> listDir(HostSystem hostSystem, SchSession session) { Channel channel = null;/*from www .j av a 2s.c o m*/ ChannelSftp c = null; String remote_dir = AppConfig.getProperty("remote_download_dir"); List<String> fileList = new ArrayList<String>(); try { channel = session.getSession().openChannel("sftp"); c = (ChannelSftp) channel; channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(CHANNEL_TIMEOUT); System.out.println(c.getHome()); Vector<ChannelSftp.LsEntry> files = c.ls(remote_dir); for (int i = 0; i < files.size(); i++) { String fileName = files.get(i).getFilename(); if (fileName.equals(".") || fileName.equals("..")) { continue; } fileList.add(fileName); } } catch (Exception e) { log.info(e.toString(), e); e.printStackTrace(); hostSystem.setErrorMsg(e.getMessage()); hostSystem.setStatusCd(HostSystem.GENERIC_FAIL_STATUS); } //exit if (c != null) { c.exit(); } //disconnect if (channel != null) { channel.disconnect(); } return fileList; }
From source file:com.buaa.cfs.net.DNS.java
/** * Returns all the host names associated by the provided nameserver with the address bound to the specified network * interface//from w w w . j a va 2 s. c om * * @param strInterface The name of the network interface or subinterface to query (e.g. eth0 or eth0:0) * @param nameserver The DNS host name * * @return A string vector of all host names associated with the IPs tied to the specified interface * * @throws UnknownHostException if the given interface is invalid */ public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { String[] ips = getIPs(strInterface); Vector<String> hosts = new Vector<String>(); for (int ctr = 0; ctr < ips.length; ctr++) { try { hosts.add(reverseDns(InetAddress.getByName(ips[ctr]), nameserver)); } catch (UnknownHostException ignored) { } catch (NamingException ignored) { } } if (hosts.isEmpty()) { LOG.warn("Unable to determine hostname for interface " + strInterface); return new String[] { cachedHostname }; } else { return hosts.toArray(new String[hosts.size()]); } }