Example usage for java.util List iterator

List of usage examples for java.util List iterator

Introduction

In this page you can find the example usage for java.util List iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this list in proper sequence.

Usage

From source file:Main.java

public static <A> boolean isPrefixOf(final List<A> ls1, final List<A> ls2) {
    if (ls1 == null) {
        return true;
    }//from  ww w  . j  a v  a  2  s.  c  o  m
    if (ls2 == null) {
        return false;
    }
    if (ls1.size() > ls2.size()) {
        return false;
    }
    final Iterator<A> iter1 = ls1.iterator();
    final Iterator<A> iter2 = ls2.iterator();
    while (iter1.hasNext()) {
        final A x1 = iter1.next();
        final A x2 = iter2.next();
        if (!x1.equals(x2)) {
            return false;
        }
    }
    return true;
}

From source file:com.aol.advertising.qiao.util.XmlConfigUtil.java

/**
 * Parse xml configuration and return a list of attributes belonging to one
 * or more elements with the specific key. It returns a list preserving the
 * order of elements in xml./*  w  w w.jav a 2 s  . c  om*/
 *
 * @param config
 * @param key
 *            identifies xml elements with the specific tag
 * @return
 */
public static List<Map<String, Object>> parseMultiNodesAttributes(HierarchicalConfiguration config,
        String key) {
    List<Map<String, Object>> result = null;

    // get a list of subnode configurations for all configuration nodes
    // selected by the given key, e.g. "node.inbound.listener"
    List<?> list = config.configurationsAt(key);
    if (list != null) {
        result = new ArrayList<Map<String, Object>>();
        for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
            HierarchicalConfiguration sub = (HierarchicalConfiguration) iter.next();
            Node root = sub.getRoot();

            Map<String, Object> attributes = new HashMap<String, Object>(root.getAttributeCount());

            // get attribute nodes
            List<?> attrs = root.getAttributes();
            for (Object attr : attrs) {
                ConfigurationNode nd = (ConfigurationNode) attr;
                attributes.put(nd.getName(), nd.getValue());
            }
            result.add(attributes);
        }
    }

    return result;
}

From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java

public static CoreModuleService getModuleServiceByCode(String countryIsoCode, String moduleName,
        int subservice) {

    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) && srv.getCoreModuleServiceSubtype() == subservice) {
                return srv;
            }//from   w  ww . j  ava  2s .  c o  m
        }
    }

    return null;

}

From source file:com.impetus.client.couchdb.CouchDBUtils.java

/**
 * Creates the view./*from  w w w .ja  v a  2 s  .  co m*/
 * 
 * @param views
 *            the views
 * @param columnName
 *            the column name
 * @param columns
 *            the columns
 */
static void createView(Map<String, MapReduce> views, String columnName, List<String> columns) {
    Iterator<String> iterator = columns.iterator();

    MapReduce mapr = new MapReduce();
    StringBuilder mapBuilder = new StringBuilder();
    StringBuilder ifBuilder = new StringBuilder("function(doc){if(");
    StringBuilder emitFunction = new StringBuilder("{emit(");
    if (columns != null && columns.size() > 1) {
        emitFunction.append("[");
    }
    while (iterator.hasNext()) {
        String nextToken = iterator.next();
        ifBuilder.append("doc." + nextToken);
        ifBuilder.append(" && ");
        emitFunction.append("doc." + nextToken);
        emitFunction.append(",");
    }
    ifBuilder.delete(ifBuilder.toString().lastIndexOf(" && "), ifBuilder.toString().lastIndexOf(" && ") + 3);
    emitFunction.deleteCharAt(emitFunction.toString().lastIndexOf(","));

    ifBuilder.append(")");
    if (columns != null && columns.size() > 1) {
        emitFunction.append("]");
    }
    emitFunction.append(", doc)}}");

    mapBuilder.append(ifBuilder.toString()).append(emitFunction.toString());

    mapr.setMap(mapBuilder.toString());
    views.put(columnName, mapr);
}

From source file:com.stratelia.webactiv.quizz.QuestionHelper.java

public static List<Answer> extractAnswer(List<FileItem> items, QuestionForm form, String componentId,
        String subdir) throws IOException {
    List<Answer> answers = new ArrayList<Answer>();
    Iterator<FileItem> iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        String mpName = item.getFieldName();
        if (item.isFormField() && mpName.startsWith("answer")) {
            String answerInput = FileUploadUtil.getOldParameter(items, mpName, "");
            Answer answer = new Answer(null, null, answerInput, 0, false, null, 0, false, null, null);
            String id = mpName.substring("answer".length());
            String nbPoints = FileUploadUtil.getOldParameter(items, "nbPoints" + id, "0");
            answer.setNbPoints(Integer.parseInt(nbPoints));
            if (Integer.parseInt(nbPoints) > 0) {
                answer.setIsSolution(true);
            }/*from  w w w  .  j a v a 2  s  .co m*/
            String comment = FileUploadUtil.getOldParameter(items, "comment" + id, "");
            answer.setComment(comment);
            String value = FileUploadUtil.getOldParameter(items, "valueImageGallery" + id, "");
            if (StringUtil.isDefined(value)) {
                // traiter les images venant de la gallery si pas d'image externe
                if (!form.isFile()) {
                    answer.setImage(value);
                }
            }
            FileItem image = FileUploadUtil.getFile(items, "image" + id);
            if (image != null) {
                addImageToAnswer(answer, image, form, componentId, subdir);
            }
            answers.add(answer);
        }
    }
    return answers;
}

From source file:net.ostis.scpdev.debug.ui.actions.BreakpointRulerAction.java

/**
 * @param markers the markers that will be removed in this function (they may be in any editor,
 *            not only in the current one)
 *///from  w w w .j  a  v a2s .  c o  m
public static void removeMarkers(List<IMarker> markers) {
    IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
    try {
        Iterator<IMarker> e = markers.iterator();
        while (e.hasNext()) {
            IBreakpoint breakpoint = breakpointManager.getBreakpoint((IMarker) e.next());
            breakpointManager.removeBreakpoint(breakpoint, true);
        }
    } catch (CoreException e) {
        log.error("Error removing markers", e);
    }
}

From source file:com.aurel.track.persist.ReflectionHelper.java

/**
 * This method replaces all occurrences of <code>ProjectType</code> 
 * value oldOID with project type value newOID going through all related
 * tables in the database./*from  www .jav  a 2s  .c o m*/
 * @param oldOID object identifier of list type to be replaced
 * @param newOID object identifier of replacement list type
 */
public static boolean hasDependentData(Class[] peerClasses, String[] fields, List<Integer> oldOIDs) {
    // Do this using reflection.
    if (oldOIDs == null || oldOIDs.isEmpty()) {
        return false;
    }
    Criteria selectCriteria;
    for (int i = 0; i < peerClasses.length; ++i) {
        Class peerClass = peerClasses[i];
        String field = fields[i];
        List<int[]> chunkList = GeneralUtils.getListOfChunks(oldOIDs);
        Iterator<int[]> iterator = chunkList.iterator();
        while (iterator.hasNext()) {
            int[] oIDsChunk = iterator.next();
            selectCriteria = new Criteria();
            selectCriteria.addIn(field, oIDsChunk);
            try {
                Class partypes[] = new Class[1];
                partypes[0] = Criteria.class;
                Method meth = peerClass.getMethod("doSelect", partypes);
                Object arglist[] = new Object[1];
                arglist[0] = selectCriteria;
                List results = (List) meth.invoke(peerClass, arglist);
                if (results != null && !results.isEmpty()) {
                    return true;
                }
            } catch (Exception e) {
                LOGGER.error("Exception when trying to find dependent data for " + "oldOIDs " + oldOIDs.size()
                        + " for class " + peerClass.toString() + " and field " + field + ": " + e.getMessage());
                LOGGER.debug(ExceptionUtils.getStackTrace(e));
            }
        }
    }
    return false;
}

From source file:io.github.jeddict.relation.mapper.spec.JoinColumnFinder.java

public static PrimaryKeyJoinColumn findPrimaryKeyJoinColumn(String name,
        List<PrimaryKeyJoinColumn> joinColumns) {
    PrimaryKeyJoinColumn joinColumn = null;
    boolean created = false;
    for (Iterator<PrimaryKeyJoinColumn> it = joinColumns.iterator(); it.hasNext();) {
        PrimaryKeyJoinColumn column = it.next();
        if (name.equals(column.getName())) {
            joinColumn = column;//from  w w w.j  a  v a 2 s.com
            created = true;
            break;
        }
    }

    if (!created) {
        joinColumn = new PrimaryKeyJoinColumn();
        joinColumn.setImplicitName(name);
        joinColumns.add(joinColumn);
    }
    return joinColumn;
}

From source file:edu.isi.webserver.FileUtil.java

static public File downloadFileFromHTTPRequest(HttpServletRequest request) {
    // Download the file to the upload file folder
    File destinationDir = new File(DESTINATION_DIR_PATH);
    logger.info("File upload destination directory: " + destinationDir.getAbsolutePath());
    if (!destinationDir.isDirectory()) {
        destinationDir.mkdir();//from  w w  w.j  ava 2s .c om
    }

    DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();

    // Set the size threshold, above which content will be stored on disk.
    fileItemFactory.setSizeThreshold(1 * 1024 * 1024); //1 MB

    //Set the temporary directory to store the uploaded files of size above threshold.
    fileItemFactory.setRepository(destinationDir);

    ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);

    File uploadedFile = null;
    try {
        // Parse the request
        @SuppressWarnings("rawtypes")
        List items = uploadHandler.parseRequest(request);
        @SuppressWarnings("rawtypes")
        Iterator itr = items.iterator();
        while (itr.hasNext()) {
            FileItem item = (FileItem) itr.next();

            // Ignore Form Fields.
            if (item.isFormField()) {
                System.out.println(item.getFieldName());
                System.out.println(item.getString());
                // Do nothing
            } else {
                //Handle Uploaded files. Write file to the ultimate location.
                System.out.println("File field name: " + item.getFieldName());
                uploadedFile = new File(destinationDir, item.getName());
                item.write(uploadedFile);
                System.out.println("File written to: " + uploadedFile.getAbsolutePath());
            }
        }
    } catch (FileUploadException ex) {
        logger.error("Error encountered while parsing the request", ex);
    } catch (Exception ex) {
        logger.error("Error encountered while uploading file", ex);
    }
    return uploadedFile;
}

From source file:morph.plugin.views.annotation.ServletAnnotationMappingUtils.java

/**
 * Check whether the given request matches the specified header conditions.
 * @param headers the header conditions, following
 *                {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()}
 * @param request the current HTTP request to check
 *///from  www . j a va 2  s.c  o  m
public static boolean checkHeaders(String[] headers, HttpServletRequest request) {
    if (!ObjectUtils.isEmpty(headers)) {
        for (String header : headers) {
            int separator = header.indexOf('=');
            if (separator == -1) {
                if (header.startsWith("!")) {
                    if (request.getHeader(header.substring(1)) != null) {
                        return false;
                    }
                } else if (request.getHeader(header) == null) {
                    return false;
                }
            } else {
                boolean negated = separator > 0 && header.charAt(separator - 1) == '!';
                String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1);
                String value = header.substring(separator + 1);
                if (isMediaTypeHeader(key)) {
                    List<MediaType> requestMediaTypes = MediaType.parseMediaTypes(request.getHeader(key));
                    List<MediaType> valueMediaTypes = MediaType.parseMediaTypes(value);
                    boolean found = false;
                    for (Iterator<MediaType> valIter = valueMediaTypes.iterator(); valIter.hasNext()
                            && !found;) {
                        MediaType valueMediaType = valIter.next();
                        for (Iterator<MediaType> reqIter = requestMediaTypes.iterator(); reqIter.hasNext()
                                && !found;) {
                            MediaType requestMediaType = reqIter.next();
                            if (valueMediaType.includes(requestMediaType)) {
                                found = true;
                            }
                        }

                    }
                    if (!found) {
                        return negated;
                    }
                } else if (!value.equals(request.getHeader(key))) {
                    return negated;
                }
            }
        }
    }
    return true;
}