List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:Main.java
/** * Group Data into {@link List}.//from ww w . ja v a2s . com * @param <T> Type of object * @param list {@link List} * @param sortBy {@link Comparator} * @param groupBy {@link Comparator} * @return {@link List} */ public static <T> List<List<T>> groupBy(final List<T> list, final Comparator<T> sortBy, final Comparator<T> groupBy) { T prev = null; List<T> currentlist = new ArrayList<>(); List<List<T>> results = new ArrayList<>(); results.add(currentlist); List<T> newlist = new ArrayList<>(list); Collections.sort(newlist, sortBy); Iterator<T> itr = newlist.iterator(); while (itr.hasNext()) { T curr = itr.next(); if (prev != null) { int result = groupBy.compare(curr, prev); if (result != 0) { currentlist = new ArrayList<>(); results.add(currentlist); } } currentlist.add(curr); prev = curr; } return results; }
From source file:Main.java
public static String join(List<String> paramList) { StringBuilder localStringBuilder = new StringBuilder(11 * paramList.size()); Iterator localIterator = paramList.iterator(); while (localIterator.hasNext()) { String str = (String) localIterator.next(); if (localStringBuilder.length() != 0) localStringBuilder.append(","); localStringBuilder.append(str);/*from www. j av a 2s . c om*/ } return localStringBuilder.toString(); }
From source file:controller.file.FileUploader.java
public static void fileUploader(HttpServletRequest req, HttpServletResponse resp) { try {/*from w w w . j a va 2s . c om*/ DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory); List<FileItem> items = servletFileUpload.parseRequest(req); Iterator<FileItem> iterator = items.iterator(); while (iterator.hasNext()) { FileItem item = iterator.next(); if (item.isFormField()) { String fileName = item.getFieldName(); String value = item.getString(); System.out.println(fileName); System.out.println(value); } else { if (!item.isFormField()) { item.write(new File("/tmp/" + item.getName())); } } } } catch (FileUploadException ex) { Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(FileUploader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
/** * @see #getAllFiles(File)// w w w . ja va 2 s. c o m */ public static List<File> getAllFiles(File directory, FileFilter filter) { final List<File> fileList = getAllFiles(directory); if (filter == null) return fileList; final Iterator<File> fileIterator = fileList.iterator(); while (fileIterator.hasNext()) { final File file = fileIterator.next(); if (!filter.accept(file)) fileList.remove(file); } return fileList; }
From source file:com.baasbox.db.hook.HooksManager.java
public static void enableHidePasswordHook(ODatabaseRecordTx db, boolean enable) { Map<ORecordHook, HOOK_POSITION> hooks = db.getHooks(); List hs = IteratorUtils.toList(hooks.keySet().iterator()); Iterator<ORecordHook> it = hs.iterator(); while (it.hasNext()) { ORecordHook h = it.next();/*w ww .java 2s. com*/ if (h instanceof HidePassword) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Enable: " + enable + " " + ((BaasBoxHook) h).getHookName() + " hook"); ((HidePassword) h).enable(enable); break; } } }
From source file:Main.java
public static String join(List<String> paramList) { StringBuilder localStringBuilder = new StringBuilder(11 * paramList.size()); Iterator localIterator = paramList.iterator(); while (localIterator.hasNext()) { String str = (String) localIterator.next(); if (localStringBuilder.length() != 0) { localStringBuilder.append(","); }//from w ww .ja v a 2 s . c o m localStringBuilder.append(str); } return localStringBuilder.toString(); }
From source file:net.sf.jasperreports.engine.export.GenericElementReportTransformer.java
/** * Applies generic element transformers of a specific key to a filled report * by replacing generic elements with the transformed elements. * //from w ww . j a v a 2 s . c o m * @param report the report * @param transformerExportKey the key used to resolve element transformers * @see GenericElementTransformer * @see GenericElementHandlerBundle#getHandler(String, String) */ public static void transformGenericElements(JasperReportsContext jasperReportsContext, JasperPrint report, String transformerExportKey) { TransformerContext transformerContext = new TransformerContext(jasperReportsContext, report); List<JRPrintPage> pages = report.getPages(); for (Iterator<JRPrintPage> pageIt = pages.iterator(); pageIt.hasNext();) { JRPrintPage page = pageIt.next(); transformElements(transformerContext, transformerExportKey, page.getElements()); } }
From source file:com.founder.fix.fixflow.explorer.util.FileHandle.java
public static Iterator<FileItem> createFactory(HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w ww . ja v a 2 s . c o m*/ // ?? servletFileUplaod DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory); // ?request??inputFileInput List<FileItem> fileItemList = servletFileUpload.parseRequest(request); return fileItemList.iterator(); } catch (Exception e) { e.printStackTrace(); throw new Exception("?!"); } }
From source file:com.baasbox.db.hook.HooksManager.java
public static void unregisteredAll(ODatabaseRecordTx db) { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("unregistering hooks..."); //OrientDB 1.7: Map<ORecordHook, HOOK_POSITION> hooks = db.getHooks(); List hs = IteratorUtils.toList(hooks.keySet().iterator()); Iterator<ORecordHook> it = hs.iterator(); while (it.hasNext()) { ORecordHook h = it.next();//w w w. j a v a 2 s. c o m if (h instanceof BaasBoxHook) { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Removing " + ((BaasBoxHook) h).getHookName() + " hook"); db.unregisterHook(h); } } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); }
From source file:com.glaf.jbpm.util.ExtensionUtils.java
public static List<Object> getValues(Map<String, Object> paramMap, Extension extension) { java.util.Date now = new java.util.Date(); List<Object> values = new java.util.ArrayList<Object>(); List<ExtensionParam> x_params = extension.getParams(); Iterator<ExtensionParam> iterator = x_params.iterator(); while (iterator.hasNext()) { ExtensionParam param = iterator.next(); String key = param.getValue(); Object value = param.getValue(); if (key != null && value != null) { String tmp = param.getValue(); if (StringUtils.isNotEmpty(tmp)) { if (tmp.equals("now()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("date()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("time()")) { value = new java.sql.Time(now.getTime()); } else if (tmp.equals("timestamp()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("dateTime()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("currentTimeMillis()")) { value = System.currentTimeMillis(); } else if (tmp.equals("#{rowId}")) { value = paramMap.get("rowId"); } else if (tmp.equals("#{processInstanceId}")) { value = ParamUtils.getLongValue(paramMap, "processInstanceId"); } else if (tmp.equals("#{processName}")) { value = ParamUtils.getString(paramMap, "processName"); } else if (tmp.equals("#{status}")) { value = paramMap.get("status"); } else if (tmp.startsWith("#P{") && tmp.endsWith("}")) { tmp = StringTools.replaceIgnoreCase(tmp, "#P{", ""); tmp = StringTools.replaceIgnoreCase(tmp, "}", ""); value = paramMap.get(tmp); } else if (tmp.startsWith("#{") && tmp.endsWith("}")) { value = DefaultExpressionEvaluator.evaluate(tmp, paramMap); }// w ww. ja va 2 s. c o m } } values.add(value); } return values; }