List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java
/** * Returns the classpath as a list of directories. Any classpath component * that is not a directory will be ignored. * /* w ww. j a v a 2 s . co m*/ * @return the classpath as a list of directories; if no directories can * be found then an empty list will be returned */ public static List getClasspathDirectories() { List directories = new ArrayList(); List components = getClasspathComponents(); for (Iterator i = components.iterator(); i.hasNext();) { String possibleDir = (String) i.next(); File file = new File(possibleDir); if (file.isDirectory()) { directories.add(possibleDir); } } List tomcatPaths = getTomcatPaths(); if (tomcatPaths != null) { directories.addAll(tomcatPaths); } return directories; }
From source file:dataMappers.PictureDataMapper.java
public static void addPictureToReport(DBConnector dbconnector, HttpServletRequest request) throws FileUploadException, IOException, SQLException { if (!ServletFileUpload.isMultipartContent(request)) { System.out.println("Invalid upload request"); return;/*from w w w . j ava2 s. co m*/ } // Define limits for disk item DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(THRESHOLD_SIZE); // Define limit for servlet upload ServletFileUpload upload = new ServletFileUpload(factory); upload.setFileSizeMax(MAX_FILE_SIZE); upload.setSizeMax(MAX_REQUEST_SIZE); FileItem itemFile = null; int reportID = 0; // Get list of items in request (parameters, files etc.) List formItems = upload.parseRequest(request); Iterator iter = formItems.iterator(); // Loop items while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { itemFile = item; // If not form field, must be item } else if (item.getFieldName().equalsIgnoreCase("reportID")) { // else it is a form field try { System.out.println(item.getString()); reportID = Integer.parseInt(item.getString()); } catch (NumberFormatException e) { reportID = 0; } } } // This will be null if no fields were declared as image/upload. // Also, reportID must be > 0 if (itemFile != null || reportID == 0) { try { // Create credentials from final vars BasicAWSCredentials awsCredentials = new BasicAWSCredentials(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY); // Create client with credentials AmazonS3 s3client = new AmazonS3Client(awsCredentials); // Set region s3client.setRegion(Region.getRegion(Regions.EU_WEST_1)); // Set content length (size) of file ObjectMetadata om = new ObjectMetadata(); om.setContentLength(itemFile.getSize()); // Get extension for file String ext = FilenameUtils.getExtension(itemFile.getName()); // Generate random filename String keyName = UUID.randomUUID().toString() + '.' + ext; // This is the actual upload command s3client.putObject(new PutObjectRequest(S3_BUCKET_NAME, keyName, itemFile.getInputStream(), om)); // Picture was uploaded to S3 if we made it this far. Now we insert the row into the database for the report. PreparedStatement stmt = dbconnector.getCon() .prepareStatement("INSERT INTO reports_pictures" + "(REPORTID, PICTURE) VALUES (?,?)"); stmt.setInt(1, reportID); stmt.setString(2, keyName); stmt.executeUpdate(); stmt.close(); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } } }
From source file:Main.java
/** * /* www .j a v a 2 s . c o m*/ * @param collection * @return double[][] */ public static double[][] to2dDoubleArray(final List<double[]> collection) { final double[][] array = new double[collection.size()][]; int i = 0; for (Iterator<double[]> iterator = collection.iterator(); iterator.hasNext();) { array[i++] = iterator.next(); } return array; }
From source file:edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils.java
public static void setNameSpacePrefixes(Model model, WebappDaoFactory wadf) { if (model == null) { log.warn("input model is null"); return;//w w w . j a va 2 s . c om } Map<String, String> prefixes = new HashMap<String, String>(); List<Ontology> ontologies = wadf.getOntologyDao().getAllOntologies(); // apparently this is null if empty if (ontologies == null) { return; } Iterator<Ontology> iter = ontologies.iterator(); String namespace = null; String prefix = null; prefixes.put("vitro", "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"); while (iter.hasNext()) { Ontology ontology = iter.next(); namespace = ontology.getURI(); // this method returns the namespace if (namespace == null || namespace.isEmpty()) { log.warn("ontology with empty namespace found"); continue; } prefix = ontology.getPrefix(); if (prefix == null || prefix.isEmpty()) { log.debug("no prefix found for namespace: " + namespace); continue; } prefixes.put(prefix, namespace); } model.setNsPrefixes(prefixes); return; }
From source file:Main.java
public static Iterator pairs(Collection l) { List x = new LinkedList(); Object prev = null;/*from w w w . ja v a2s . c om*/ for (Iterator i = l.iterator(); i.hasNext();) { Object curr = i.next(); if (prev != null) x.add(new Object[] { prev, curr }); prev = curr; } return x.iterator(); }
From source file:com.amalto.core.initdb.InitDBUtil.java
private static void updateDB(String resourcePath, Map<String, List<String>> initdb) { for (Entry<String, List<String>> entry : initdb.entrySet()) { String dataCluster = entry.getKey(); try {//from w ww .j a v a 2 s . co m ConfigurationHelper.createCluster(dataCluster);// slow but more reliable } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Could not create cluster.", e); //$NON-NLS-1$ } } List<String> list = entry.getValue(); // create items Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) { String item = iterator.next(); try { InputStream in = InitDBUtil.class.getResourceAsStream(resourcePath + "/" + item); //$NON-NLS-1$ String xmlString = IOUtils.toString(in, "UTF-8"); //$NON-NLS-1$ String uniqueID = item; int pos = item.lastIndexOf('/'); if (pos != -1) { uniqueID = item.substring(pos + 1); } uniqueID = uniqueID.replaceAll("\\+", " "); //$NON-NLS-1$ //$NON-NLS-2$ if (Boolean.valueOf((String) MDMConfiguration.getConfiguration().get("cluster_override"))) { //$NON-NLS-1$ ConfigurationHelper.deleteDocument(dataCluster, uniqueID); } ConfigurationHelper.putDocument(dataCluster, xmlString, uniqueID); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Could not delete document.", e); //$NON-NLS-1$ } } finally { iterator.remove(); } } } }
From source file:ebay.dts.client.BulkDataExchangeCall.java
public static Map insertHttpsHeadersMap(String name, Map<String, List<String>> maplist) { StringBuilder builder = new StringBuilder(); builder.append("=== " + name + "\n"); Map headers = new HashMap<String, Object>(); Iterator headerIter = null;//from w ww .j a v a2s. c o m if (maplist != null) { maplist.entrySet(); headerIter = maplist.keySet().iterator(); while (headerIter.hasNext()) { String key = (String) headerIter.next(); builder.append("Key: " + key); List l = (List<String>) maplist.get(key); Iterator iter = l.iterator(); String value = null; while (iter.hasNext()) { value = (String) iter.next(); builder.append("; Value: " + value + "\n"); } headers.put(key, value); } } logger.debug(builder.toString()); return headers; }
From source file:Main.java
public static void removeDuplicateWithOrder(List<ResolveInfo> list) { if (list == null) { return;//from w w w . j ava 2 s.co m } Set<String> set = new HashSet<String>(); List<ResolveInfo> newList = new ArrayList<ResolveInfo>(); for (Iterator<ResolveInfo> iter = list.iterator(); iter.hasNext();) { ResolveInfo info = (ResolveInfo) iter.next(); if (set.add(info.activityInfo.packageName)) { newList.add(info); } } list.clear(); list.addAll(newList); }
From source file:Statistics.java
public static int[] mode(final int[] list) throws IllegalArgumentException { if (list.length == 0) { throw new IllegalArgumentException(LOG_ARRAY_LENGTH_0); }//from w w w . ja v a2 s.co m final ModeCompute<Integer> modeComp = new ModeCompute<Integer>(); for (int i = 0; i < list.length; i++) { modeComp.add(list[i]); } final List<Integer> l = modeComp.getMode(); // Prepare the output array: final int[] out = new int[l.size()]; Iterator<Integer> itr = l.iterator(); for (int i = 0; i < out.length; i++) { out[i] = itr.next(); } return out; }
From source file:com.impetus.kvapps.runner.ExecutorService.java
private static void printTweets(List<User> users) { for (Iterator<User> iterator = users.iterator(); iterator.hasNext();) { User user = (User) iterator.next(); Iterator<Tweets> tweets = users.get(0).getTweets().iterator(); int counter = 1; while (tweets.hasNext()) { logger.info("\n"); logger.info("\t\t Tweet No:#" + counter++); Tweets rec = tweets.next();// w w w . jav a 2 s .c o m logger.info("\t\t tweet is ->" + rec.getBody()); logger.info("\t\t Tweeted at ->" + rec.getTweetDate()); if (rec.getVideos() != null) { logger.info("\t\t Tweeted Contains Video ->" + rec.getVideos().size()); for (Iterator iteratorVideo = rec.getVideos().iterator(); iteratorVideo.hasNext();) { Video video = (Video) iteratorVideo.next(); logger.info(video); } } } } }