List of usage examples for java.util Vector isEmpty
public synchronized boolean isEmpty()
From source file:routercc8.DistanceVector.java
public DistanceVector() { this.nombre = "A"; String read;//from www.ja v a 2 s .c o m hasChanged = true; try { archivo = new BufferedReader(new FileReader("./src/routercc8/conf.ini")); while ((read = archivo.readLine()) != null) { String[] arr = read.split(":"); dv.add(nombre + ":" + arr[0] + ":" + arr[1]); adyacentes++; ady.put(arr[0], 0); //saber cuales son adyacentes mins.put(arr[0], arr[0] + ":" + arr[1]); //A-B:3 //A-C:23 } Vector newmin = new Vector(); System.out.println("Start:" + mins.toString()); System.out.println(dv.toString()); recibeMinimo("A", "B", 3); recibeMinimo("A", "C", 23); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("1nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); recibeMinimo("C", "D", 5); recibeMinimo("C", "B", 2); recibeMinimo("C", "A", 23); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("2nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); recibeMinimo("D", "C", 5); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("3nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); System.out.println("T1"); System.out.println(); //T = 1; recibeMinimo("A", "C", 5); recibeMinimo("A", "D", 28); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("4nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); recibeMinimo("C", "A", 5); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("5nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); recibeMinimo("D", "A", 28); recibeMinimo("D", "B", 7); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("6nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); //T=2 System.out.println("T2"); System.out.println(); recibeMinimo("D", "A", 10); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("7nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(dv.toString()); recibeMinimo("A", "D", 99); newmin = calcular(); if (!newmin.isEmpty()) { System.out.println("8nuevos Minimos: " + newmin.toString()); } System.out.println(mins.toString()); System.out.println(getMin("D")); System.out.println(dv.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.image.defaults.DefaultRepository.java
protected FileListing[] listFilesImpl(String ownerID, String[] nameScoped, String[] ownerScoped) throws Exception { if (ownerID == null) { throw new CannotTranslateException("Cannot contact repository " + "without owner ID"); }// w ww . j av a 2 s. c o m final String directoryURLstr = this.getBaseDirectory() + "/" + ownerID + "/"; final GlobusURL listdir = new GlobusURL(directoryURLstr); final GridFTPClient client = new GridFTPClient(listdir.getHost(), listdir.getPort()); final String idauthz = this.getIdAuthz(); if (idauthz == null) { client.setAuthorization(HostAuthorization.getInstance()); } else { final IdentityAuthorization idA = new IdentityAuthorization(idauthz); client.setAuthorization(idA); } client.authenticate(null); client.setType(Session.TYPE_ASCII); client.setPassive(); client.setLocalActive(); client.changeDir(listdir.getPath()); final Vector v = client.mlsd(null); int len = v.size(); final ArrayList files = new ArrayList(len); while (!v.isEmpty()) { final MlsxEntry f = (MlsxEntry) v.remove(0); if (f == null) { continue; // *** SKIP *** } final String fileName = f.getFileName(); if (fileName == null) { continue; // *** SKIP *** } if (fileName.equals(".")) { len -= 1; continue; // *** SKIP *** } if (fileName.equals("..")) { len -= 1; continue; // *** SKIP *** } if (nameScoped == null || nameScoped.length == 0) { final FileListing listing = this.getOneListing(f, ownerScoped); if (listing != null) { files.add(listing); } } else { for (int i = 0; i < nameScoped.length; i++) { if (fileName.equals(nameScoped[i])) { final FileListing listing = this.getOneListing(f, ownerScoped); if (listing != null) { files.add(listing); } break; // assuming unique file names.. } } } } client.close(); return (FileListing[]) files.toArray(new FileListing[files.size()]); }
From source file:org.freeplane.main.addons.AddOnProperties.java
private Map<String, Map<String, String>> parseTranslations(Vector<XMLElement> xmlElements) { final Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>(); if (xmlElements != null && !xmlElements.isEmpty()) { for (XMLElement xmlElement : xmlElements.get(0).getChildren()) { Map<String, String> properties = new LinkedHashMap<String, String>(); result.put(xmlElement.getAttribute("name", null), properties); for (XMLElement entryXmlElement : xmlElement.getChildren()) { properties.put(entryXmlElement.getAttribute("key", null), entryXmlElement.getContent()); }//from w w w. j a va 2 s.c o m } } return result; }
From source file:prodoc.DriverRemote.java
/** * Retrieves next record of cursor// w w w.ja v a2 s. co m * @param CursorIdent * @return OPD next Record * @throws PDException */ @Override public Record NextRec(Cursor CursorIdent) throws PDException { if (PDLog.isDebug()) PDLog.Debug("DriverRemote.NextRec:" + CursorIdent); Vector rs = (Vector) CursorIdent.getResultSet(); if (rs.isEmpty()) return (null); Record Fields = CursorIdent.getFieldsCur(); Fields.assignSimil((Record) rs.get(0)); // description and other elemens from atribute not transmitted by performance rs.remove(0); return (Fields.Copy()); }
From source file:org.ops4j.pax.web.service.spi.util.ResourceDelegatingBundleClassLoader.java
protected URL findResource(String name) { Vector<URL> resources = getFromCache(name); if (resources == null) { resources = new Vector<>(); for (Bundle delegate : bundles) { try { URL resource = delegate.getResource(name); if (resource != null) { resources.add(resource); break; }/*w ww . j ava2s. c om*/ } catch (IllegalStateException exc) { // ignore } } if (!resources.isEmpty()) { addToCache(name, resources); } } Enumeration<URL> elements = resources.elements(); if (elements.hasMoreElements()) { return elements.nextElement(); } return null; }
From source file:org.mahasen.util.SearchUtil.java
/** * @param propertyName//from w ww. jav a2s . c om * @param propertyValue * @return * @throws InterruptedException * @throws MahasenException */ private Vector<Id> getSearchResultIds(String propertyName, String propertyValue) throws InterruptedException, MahasenException { Vector<Id> idVector = new Vector<Id>(); // tag search for several tags if (propertyValue.contains("&")) { String values[] = propertyValue.split("\\&"); for (String value : values) { if (idVector.isEmpty()) { Vector<Id> tempResult = mahasenManager.getSearchResults(propertyName, value.trim()); if (tempResult != null) { idVector.addAll(tempResult); } } if (!idVector.isEmpty()) { Stack<Vector<Id>> idVectorSet = new Stack<Vector<Id>>(); idVectorSet.push(idVector); idVectorSet.push(mahasenManager.getSearchResults(propertyName, value.trim())); idVector = getCommonIds(idVectorSet); } } } else if (propertyValue.contains("|")) { String values[] = propertyValue.split("\\|"); for (String value : values) { Vector<Id> tempResult = mahasenManager.getSearchResults(propertyName, value.trim()); if (tempResult != null) { for (Id id : tempResult) { if (!idVector.contains(id)) { idVector.add(id); } } } } } else { idVector = mahasenManager.getSearchResults(propertyName, propertyValue.trim()); } return idVector; }
From source file:fsi_admin.JSmtpConn.java
@SuppressWarnings("rawtypes") private boolean adjuntarArchivo(StringBuffer msj, BodyPart messagebodypart, MimeMultipart multipart, Vector archivos) { if (!archivos.isEmpty()) { FileItem actual = null;// w w w . j av a2 s .co m try { for (int i = 0; i < archivos.size(); i++) { InputStream inputStream = null; try { actual = (FileItem) archivos.elementAt(i); inputStream = actual.getInputStream(); byte[] sourceBytes = IOUtils.toByteArray(inputStream); String name = actual.getName(); messagebodypart = new MimeBodyPart(); ByteArrayDataSource rawData = new ByteArrayDataSource(sourceBytes); DataHandler data = new DataHandler(rawData); messagebodypart.setDataHandler(data); messagebodypart.setFileName(name); multipart.addBodyPart(messagebodypart); //////////////////////////////////////////////// /* messagebodypart = new MimeBodyPart(); DataSource source = new FileDataSource(new File(actual.getName())); byte[] sourceBytes = actual.get(); OutputStream sourceOS = source.getOutputStream(); sourceOS.write(sourceBytes); messagebodypart.setDataHandler(new DataHandler(source)); messagebodypart.setFileName(actual.getName()); multipart.addBodyPart(messagebodypart); */ /////////////////////////////////////////////////////// } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } catch (MessagingException e) { e.printStackTrace(); msj.append("Error de Mensajeria al cargar adjunto SMTP: " + e.getMessage()); return false; } catch (IOException e) { e.printStackTrace(); msj.append("Error de Entrada/Salida al cargar adjunto SMTP: " + e.getMessage()); return false; } } else return true; }
From source file:org.kepler.ssh.LocalDelete.java
/** * Recursively traverse the directories looking for matches on each level to * the relevant part of the mask. Matched files will be deleted. Matched * directories will be deleted only if 'recursive' is true. *//* www. ja v a 2s. c o m*/ private boolean delete(File node, Vector masks, boolean recursive) { if (isDebugging) log.debug(">>> " + node.getPath() + " with masks length = " + masks.size() + ": " + masks.toString()); // the query is for a single file/dir --> it will be deleted now if (masks.isEmpty()) { return deleteNode(node, recursive, "Delete "); } // handle the case where path is not a directory but something else if (!node.isDirectory()) { if (node.isFile()) { // single file // this file cannot match the rest of the query mask return true; // this is not an error, just skip } else { // wildcardless mask referred to a non-existing file/dir log.error("Path " + node.getPath() + " is not a directory!"); return false; } } // path refers to an existing dir. // Let's list its content with the appropriate mask String localMask = null; Vector restMask = (Vector) masks.clone(); if (!masks.isEmpty()) { localMask = (String) masks.firstElement(); // first element as local // mask restMask.remove(0); // the rest } boolean result = true; // will become false if at least one file removal // fails // handle special masks . and .. separately if (localMask.equals(".") || localMask.equals("..")) { // we just need to call this method again with the next mask File newNode = new File(node, localMask); if (isDebugging) log.debug("Special case of " + localMask + " --> Call delete() with " + newNode.getPath()); result = delete(newNode, restMask, recursive); } else { // meaningful mask... so list the directory and recursively traverse // directories MyLocalFilter localFilter = new MyLocalFilter(localMask); // Get files matching the localMask in the dir 'node' File[] files = node.listFiles(localFilter); if (isDebugging) log.debug("Found " + files.length + " matching files in " + node); for (int i = 0; i < files.length; i++) { // recursive call with the rest of the masks boolean succ = delete(files[i], restMask, recursive); if (!succ && isDebugging) log.debug("Failed removal of " + files[i].getPath()); result = result && succ; } } if (isDebugging) log.debug("<<< " + node.getPath()); return result; }
From source file:org.apache.oodt.cas.workflow.gui.model.repo.XmlWorkflowModelRepository.java
private void ensureUniqueIds(Set<ModelGraph> graphs) { for (ModelGraph graph : graphs) { HashSet<String> names = new HashSet<String>(); Vector<ModelGraph> stack = new Vector<ModelGraph>(); stack.add(graph);// w w w . jav a 2 s . c o m while (!stack.isEmpty()) { ModelGraph currentGraph = stack.remove(0); String currentId = currentGraph.getId(); for (int i = 1; names.contains(currentId); i++) { currentId = currentGraph.getId() + "-" + i; } names.add(currentId); if (!currentId.equals(currentGraph.getId())) { currentGraph.getModel().setModelId(currentId); } stack.addAll(currentGraph.getChildren()); } } }
From source file:fsi_admin.JAwsS3Conn.java
@SuppressWarnings("rawtypes") private boolean subirArchivo(StringBuffer msj, AmazonS3 s3, String S3BUKT, String nombre, Vector archivos) { //System.out.println("AwsConn SubirArchivo:" + nombre + ":nombre"); if (!archivos.isEmpty()) { FileItem actual = null;/*ww w. j av a 2 s .com*/ try { for (int i = 0; i < archivos.size(); i++) { InputStream inputStream = null; try { actual = (FileItem) archivos.elementAt(i); ///////////////////////////////////////////////////////// //Obtain the Content length of the Input stream for S3 header InputStream is = actual.getInputStream(); byte[] contentBytes = IOUtils.toByteArray(is); Long contentLength = Long.valueOf(contentBytes.length); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(contentLength); //Reobtain the tmp uploaded file as input stream inputStream = actual.getInputStream(); //Put the object in S3 //System.out.println("BUCKET: " + S3BUKT + " OBJETO: " + nombre.replace('_', '-')); //System.out.println("BUCKET: " + S3BUKT + " OBJETO: " + nombre.replace('_', '-')); s3.putObject(new PutObjectRequest(S3BUKT, nombre, inputStream, metadata)); } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } //////////////////////////////////////////////////////////// } return true; } catch (AmazonServiceException ase) { ase.printStackTrace(); msj.append("Error de AmazonServiceException al subir archivo a S3.<br>"); msj.append("Mensaje: " + ase.getMessage() + "<br>"); msj.append("Cdigo de Estatus HTTP: " + ase.getStatusCode() + "<br>"); msj.append("Cdigo de Error AWS: " + ase.getErrorCode() + "<br>"); msj.append("Tipo de Error: " + ase.getErrorType() + "<br>"); msj.append("Request ID: " + ase.getRequestId()); return false; } catch (AmazonClientException ace) { ace.printStackTrace(); msj.append("Error de AmazonClientException al subir archivo a S3.<br>"); msj.append("Mensaje: " + ace.getMessage()); return false; } catch (IOException e) { e.printStackTrace(); msj.append("Error de Entrada/Salida al subir archivo a S3: " + e.getMessage()); return false; } } else { msj.append("Error al subir archivo a la nube: No se envi ningun archivo"); return false; } }