List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:com.liferay.apio.architect.internal.body.MultipartToBodyConverter.java
/** * Reads a {@code "multipart/form"} HTTP request body into a {@link Body} * instance or fails with a {@link BadRequestException} if the input is not * a valid multipart form.//from w w w . ja v a 2 s. com * * @review */ public static Body multipartToBody(HttpServletRequest request) { if (!isMultipartContent(request)) { throw new BadRequestException("Request body is not a valid multipart form"); } FileItemFactory fileItemFactory = new DiskFileItemFactory(); ServletFileUpload servletFileUpload = new ServletFileUpload(fileItemFactory); try { List<FileItem> fileItems = servletFileUpload.parseRequest(request); Iterator<FileItem> iterator = fileItems.iterator(); Map<String, String> values = new HashMap<>(); Map<String, BinaryFile> binaryFiles = new HashMap<>(); Map<String, Map<Integer, String>> indexedValueLists = new HashMap<>(); Map<String, Map<Integer, BinaryFile>> indexedFileLists = new HashMap<>(); while (iterator.hasNext()) { FileItem fileItem = iterator.next(); String name = fileItem.getFieldName(); Matcher matcher = _arrayPattern.matcher(name); if (matcher.matches()) { int index = Integer.parseInt(matcher.group(2)); String actualName = matcher.group(1); _storeFileItem(fileItem, value -> { Map<Integer, String> indexedMap = indexedValueLists.computeIfAbsent(actualName, __ -> new HashMap<>()); indexedMap.put(index, value); }, binaryFile -> { Map<Integer, BinaryFile> indexedMap = indexedFileLists.computeIfAbsent(actualName, __ -> new HashMap<>()); indexedMap.put(index, binaryFile); }); } else { _storeFileItem(fileItem, value -> values.put(name, value), binaryFile -> binaryFiles.put(name, binaryFile)); } } Map<String, List<String>> valueLists = _flattenMap(indexedValueLists); Map<String, List<BinaryFile>> fileLists = _flattenMap(indexedFileLists); return Body.create(key -> Optional.ofNullable(values.get(key)), key -> Optional.ofNullable(valueLists.get(key)), key -> Optional.ofNullable(fileLists.get(key)), key -> Optional.ofNullable(binaryFiles.get(key))); } catch (FileUploadException | IndexOutOfBoundsException | NumberFormatException e) { throw new BadRequestException("Request body is not a valid multipart form", e); } }
From source file:de.laures.cewolf.util.Renderer.java
public static void removeLegend(JFreeChart chart) { List subTitles = chart.getSubtitles(); Iterator iter = subTitles.iterator(); while (iter.hasNext()) { Object o = iter.next();/* w w w .j av a 2 s . c om*/ if (o instanceof LegendTitle) { iter.remove(); break; } } }
From source file:de.laures.cewolf.util.Renderer.java
public static LegendTitle getLegend(JFreeChart chart) { //i need to find the legend now. LegendTitle legend = null;//from w w w. j ava2s. c o m List subTitles = chart.getSubtitles(); Iterator iter = subTitles.iterator(); while (iter.hasNext()) { Object o = iter.next(); if (o instanceof LegendTitle) { legend = (LegendTitle) o; break; } } return legend; }
From source file:com.doculibre.constellio.servlets.DownloadFileServlet.java
public static String getFilePathFor(String file) { List<String> downloadDirs = ConstellioSpringUtils.getFileDownloadDirs(); if (downloadDirs == null) { throw new RuntimeException("No download dirs specified"); }/*from www .j a v a 2 s . c o m*/ Iterator<String> itDirs = downloadDirs.iterator(); String filePathFound = null; while (filePathFound == null && itDirs.hasNext()) { String dir = itDirs.next(); if (new File(file).exists()) { if (file.contains(dir)) { filePathFound = file; } } else { File test = new File(dir, file); if (test.exists()) { filePathFound = test.getAbsolutePath(); } } } return filePathFound; }
From source file:eu.impact_project.iif.t2.client.Helper.java
/** * Extracts all the form input values from a request object. Taverna * workflows are read as strings. Other files are converted to Base64 * strings.// w w w. j a va 2 s . c om * * @param request * The request object that will be analyzed * @return Map containing all form values and files as strings. The name of * the form is used as the index */ public static Map<String, String> parseRequest(HttpServletRequest request) { // stores all the strings and encoded files from the html form Map<String, String> htmlFormItems = new HashMap<String, String>(); try { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List items; items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); // a normal string field if (item.isFormField()) { // put the string items into the map htmlFormItems.put(item.getFieldName(), item.getString()); // uploaded workflow file } else if (item.getFieldName().startsWith("file_workflow")) { htmlFormItems.put(item.getFieldName(), new String(item.get())); // uploaded file } else { // encode the uploaded file to base64 String currentAttachment = new String(Base64.encode(item.get())); // put the encoded attachment into the map htmlFormItems.put(item.getFieldName(), currentAttachment); } } } catch (FileUploadException e) { e.printStackTrace(); } return htmlFormItems; }
From source file:de.berlios.jhelpdesk.model.TicketPriority.java
public static String listAsString(List<TicketPriority> inputList) { StringBuilder tpBuf = new StringBuilder(""); if (inputList != null) { for (Iterator<TicketPriority> it = inputList.iterator(); it.hasNext();) { tpBuf.append(it.next().toInt()); if (it.hasNext()) { tpBuf.append(","); }// ww w. java 2 s. c o m } } return tpBuf.toString(); }
From source file:StringUtils.java
/** * Returns an array of strings, one for each line in the string after it has * been wrapped to fit lines of <var>maxWidth</var>. Lines end with any of * cr, lf, or cr lf. A line ending at the end of the string will not output a * further, empty string.//w ww.j a v a 2s . c o m * <p> * This code assumes <var>str</var> is not <code>null</code>. * * @param str * the string to split * @param fm * needed for string width calculations * @param maxWidth * the max line width, in points * @return a non-empty list of strings */ public static List wrap(String str, FontMetrics fm, int maxWidth) { List lines = splitIntoLines(str); if (lines.size() == 0) return lines; ArrayList strings = new ArrayList(); for (Iterator iter = lines.iterator(); iter.hasNext();) wrapLineInto((String) iter.next(), strings, fm, maxWidth); return strings; }
From source file:com.meetme.plugins.jira.gerrit.webpanel.GerritReviewsIssueLeftPanel.java
private static int removeClosedReviews(List<GerritChange> changes) { Iterator<GerritChange> it = changes.iterator(); int c = 0;//from w w w. j av a 2s . c o m while (it.hasNext()) { GerritChange change = it.next(); if (!change.isOpen()) { it.remove(); c += 1; } } return c; }
From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java
public static CoreModuleService getModuleServiceByCode(String countryIsoCode, String moduleName) { List services = ServicesUtil.getServices(countryIsoCode); if (services != null) { Iterator i = services.iterator(); while (i.hasNext()) { CoreModuleService srv = (CoreModuleService) i.next(); if (srv.getCoreModuleName().equals(moduleName)) { return srv; }/* w w w.j a v a 2s . co m*/ } } return null; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.helpers.FinalTableExtractor.java
@Deprecated public static void extractCDResults(String inFile, String outFile) throws IOException { File file = new File(inFile); Table<String, String, String> table = TreeBasedTable.create(); List<String> lines = IOUtils.readLines(new FileInputStream(file)); Iterator<String> iterator = lines.iterator(); while (iterator.hasNext()) { String featureSet = iterator.next(); // shorten fs name featureSet = featureSet.replaceAll("^\\./", ""); // extract domain DocumentDomain domain = null;//from www . j a v a 2 s. c o m for (DocumentDomain currentDomain : DocumentDomain.values()) { if (featureSet.contains(currentDomain.toString())) { if (domain != null) { throw new IllegalStateException("!!!"); } domain = currentDomain; } } if (domain == null) { throw new IllegalStateException("No domain found! " + featureSet); } String shortFeatureSet = featureSet.replaceAll("/.*", ""); System.out.println(shortFeatureSet); String[] fsSettings = shortFeatureSet.split("_", 6); String clusters = fsSettings[4]; if (includeRow(clusters)) { table.put(shortFeatureSet, "FS", fsSettings[1]); } // 12 lines with results for (int i = 0; i < 12; i++) { String line = iterator.next(); String[] split = line.split("\\s+"); String measure = split[0]; Double value = Double.valueOf(split[1]); // only a50 and a100,s1000 if (includeRow(clusters)) { table.put(shortFeatureSet, "Clusters", clusters); if (includeColumn(measure)) { table.put(shortFeatureSet, domain.toString() + measure, String.format(Locale.ENGLISH, "%.3f", value)); } } } } // tableToCsv(table, new FileWriter(outFile)); }