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:net.sourceforge.fenixedu.util.InquiriesUtil.java

/**
 * @return Returns the list containing with only the first occurrence of the
 *         elementes based on the equals method the result list is ordered
 *         by the externalId/*from www .  j a  va  2s  .  c o m*/
 */
public static void removeDuplicates(final List beanList) {
    if (beanList.isEmpty()) {
        return;
    }

    Collections.sort(beanList, new BeanComparator("externalId"));

    final Iterator iter = beanList.iterator();
    InfoObject prev = (InfoObject) iter.next();
    while (iter.hasNext()) {
        final InfoObject curr = (InfoObject) iter.next();
        if (curr.equals(prev)) {
            iter.remove();
        }
        prev = curr;
    }
}

From source file:com.tek271.reverseProxy.servlet.ProxyFilter.java

private static MultipartEntity getMultipartEntity(HttpServletRequest request) {
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    Enumeration<String> en = request.getParameterNames();
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        String value = request.getParameter(name);
        try {/*from   www . ja v a2s.  c  om*/
            if (name.equals("file")) {
                FileItemFactory factory = new DiskFileItemFactory();
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(10000000);// 10 Mo
                List items = upload.parseRequest(request);
                Iterator itr = items.iterator();
                while (itr.hasNext()) {
                    FileItem item = (FileItem) itr.next();
                    File file = new File(item.getName());
                    FileOutputStream fos = new FileOutputStream(file);
                    fos.write(item.get());
                    fos.flush();
                    fos.close();
                    entity.addPart(name, new FileBody(file, "application/zip"));
                }
            } else {
                entity.addPart(name, new StringBody(value.toString(), "text/plain", Charset.forName("UTF-8")));
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileUploadException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (FileNotFoundException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }

    return entity;

}

From source file:edu.common.dynamicextensions.xmi.XMIUtilities.java

/**
 * This method gets the super class for the given UmlClass
 * @param klass//from w w  w.ja  v a  2  s  .  c  o  m
 * @return
 */
public static UmlClass getSuperClass(UmlClass klass) {
    UmlClass superClass = null;
    List superClasses = getSuperClasses(klass);
    if (superClasses.size() > 0) {
        superClass = (UmlClass) superClasses.iterator().next();
    }
    return superClass;
}

From source file:com.aw.swing.mvp.ui.painter.PainterMessages.java

private static JComponent getComponentThatRecivedFocus(Throwable exception) {
    BindingComponent bindingComponent = null;
    if (exception instanceof AWException) {
        if (exception instanceof AWValidationException) {
            if (((AWValidationException) exception).getListObject() != null
                    && ((AWValidationException) exception).getListObject().size() > 0) {
                List exceptions = ((AWValidationException) exception).getListObject();
                for (Iterator iterator = exceptions.iterator(); iterator.hasNext();) {
                    AWValidationException o = (AWValidationException) iterator.next();
                    if (o.getJComponent() != null) {
                        bindingComponent = (BindingComponent) (o.getJComponent())
                                .getClientProperty(BindingComponent.ATTR_BND);
                        if (!bindingComponent.isUiReadOnly()) {
                            return bindingComponent.getJComponent();
                        }/*w ww  .j a va 2 s.  com*/
                    }
                }
            }
        }
        if ((exception instanceof AWSwingException) && ((AWSwingException) exception).getJComponent() != null) {
            JComponent jComponent = ((AWSwingException) exception).getJComponent();
            bindingComponent = (BindingComponent) jComponent.getClientProperty(BindingComponent.ATTR_BND);
            if (!bindingComponent.isUiReadOnly()) {
                return bindingComponent.getJComponent();
            }
        }

    }

    if (oldComponents.size() > 0) {
        for (Iterator iterator = oldComponents.iterator(); iterator.hasNext();) {
            bindingComponent = (BindingComponent) iterator.next();
            if (!bindingComponent.isUiReadOnly()) {
                return bindingComponent.getJComponent();
            }
        }
    }

    return null;
}

From source file:com.continuent.tungsten.common.commands.DirectoryCommands.java

/**
 * Deletes files in a directory matching a specific pattern
 * //from   www .  j  a  v a2  s  .c  o  m
 * @param directoryPath the directory to delete files in
 */
public static boolean deleteFiles(String directoryPath) {
    int filesDeletedCount = 0;

    List<String> files = fileList(directoryPath, true);
    Iterator<String> filesIterator = files.iterator();
    while (filesIterator.hasNext()) {
        String file = filesIterator.next();
        deleteFile(file);
        filesDeletedCount++;
    }

    return (filesDeletedCount > 0 ? true : false);
}

From source file:com.runwaysdk.business.generation.maven.MavenClasspathBuilder.java

public static List<String> getClasspathFromMavenProject(File projectPom, File localRepoFolder,
        boolean isRunwayEnvironment) throws DependencyResolutionException, IOException, XmlPullParserException {
    MavenProject proj = loadProject(projectPom);

    PropertyReplacer propReplacer = new PropertyReplacer(proj);

    List<Repository> repos = proj.getRepositories();

    List<String> classpath = new ArrayList<String>();

    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system, localRepoFolder);
    RemoteRepository centralRepo = Booter.newCentralRepository();
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);

    List<org.apache.maven.model.Dependency> dependencies = proj.getDependencies();
    Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();

    while (it.hasNext()) {
        org.apache.maven.model.Dependency depend = it.next();

        Artifact artifact = new DefaultArtifact(propReplacer.replace(depend.getGroupId()),
                propReplacer.replace(depend.getArtifactId()), propReplacer.replace(depend.getClassifier()),
                propReplacer.replace(depend.getType()), propReplacer.replace(depend.getVersion()));

        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
        collectRequest.addRepository(centralRepo);

        for (Repository repo : repos) {
            collectRequest.addRepository(new RemoteRepository(propReplacer.replace(repo.getId()),
                    propReplacer.replace(repo.getLayout()), propReplacer.replace(repo.getUrl())));
        }/*from  w  w  w.  ja  v a2 s. co m*/

        try {
            DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);

            List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest)
                    .getArtifactResults();

            for (ArtifactResult artifactResult : artifactResults) {
                Artifact art = artifactResult.getArtifact();

                if (isRunwayEnvironment && art.getGroupId().equals("com.runwaysdk")
                        && (art.getArtifactId().equals("runwaysdk-client")
                                || art.getArtifactId().equals("runwaysdk-common")
                                || art.getArtifactId().equals("runwaysdk-server"))) {
                    continue;
                }

                classpath.add(art.getFile().getAbsolutePath());
            }
        } catch (DependencyResolutionException e) {
            // Is Maven ignoring this? I'm confused.
            log.error(e);
            e.printStackTrace();
        }
    }

    if (log.isTraceEnabled()) {
        String cpath = "";
        for (Iterator<String> i = classpath.iterator(); i.hasNext();) {
            cpath = cpath + ", " + i.next();
        }

        log.trace("Resolved pom [" + projectPom.getAbsolutePath() + "] classpath to [" + cpath + "]");
    }

    return classpath;
}

From source file:io.takari.maven.testing.executor.ForkedLauncher.java

static String extractMavenVersion(List<String> logLines) {
    String version = null;/*  w  w  w  .  j ava 2 s  . com*/

    final Pattern mavenVersion = Pattern.compile("(?i).*Maven.*? ([0-9]\\.\\S*).*");

    for (Iterator<String> it = logLines.iterator(); version == null && it.hasNext();) {
        String line = it.next();

        Matcher m = mavenVersion.matcher(line);
        if (m.matches()) {
            version = m.group(1);
        }
    }

    return version;
}

From source file:at.bestsolution.persistence.java.Util.java

public static <O> void syncLists(List<O> targetList, List<O> newList) {
    Iterator<O> it = targetList.iterator();
    List<O> removeItems = new ArrayList<O>();
    // remove items not found in new list
    // do not remove immediately because because then to many notifications
    // are regenerated
    while (it.hasNext()) {
        O next = it.next();//from w w  w.  j  a v a  2s .  c o m
        if (!newList.contains(next)) {
            removeItems.add(next);
        }
    }

    targetList.removeAll(removeItems);

    // remove all items from the new list already contained
    it = newList.iterator();
    while (it.hasNext()) {
        if (targetList.contains(it.next())) {
            it.remove();
        }
    }

    targetList.addAll(newList);
}

From source file:com.astamuse.asta4d.web.form.flow.base.BasicFormFlowTraitHelper.java

static final List<AnnotatedPropertyInfo> retrieveRenderTargetFieldList(Object form) {
    List<AnnotatedPropertyInfo> list = RenderingTargetFieldsMap.get(form.getClass().getName());
    if (list == null) {
        list = new LinkedList<AnnotatedPropertyInfo>(AnnotatedPropertyUtil.retrieveProperties(form.getClass()));
        Iterator<AnnotatedPropertyInfo> it = list.iterator();
        while (it.hasNext()) {
            // remove all the non form field properties
            if (it.next().getAnnotation(FormField.class) == null) {
                it.remove();//from   w  w  w .java 2s .  c  o  m
            }
        }
        RenderingTargetFieldsMap.put(form.getClass().getName(), list);
    }
    return list;
}

From source file:it.serverSystem.ClusterTest.java

private static String getPropertyValue(Orchestrator web, String property) {
    Settings.ValuesWsResponse response = ItUtils.newAdminWsClient(web).settingsService()
            .values(ValuesRequest.builder().setKeys(property).build());
    List<Settings.Setting> settingsList = response.getSettingsList();
    if (settingsList.isEmpty()) {
        return null;
    }/*from  www.j a v a2 s  .c  o  m*/
    assertThat(settingsList).hasSize(1);
    return settingsList.iterator().next().getValue();
}