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.dataTransferObject.InfoExecutionDegree.java

public static List buildLabelValueBeansForList(List executionDegrees, MessageResources messageResources) {
    List copyExecutionDegrees = new ArrayList();
    copyExecutionDegrees.addAll(executionDegrees);
    List result = new ArrayList();
    Iterator iter = executionDegrees.iterator();
    while (iter.hasNext()) {
        final InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) iter.next();
        List equalDegrees = (List) CollectionUtils.select(copyExecutionDegrees, new Predicate() {
            @Override/*from  w ww  .jav  a 2s  . c o m*/
            public boolean evaluate(Object arg0) {
                InfoExecutionDegree infoExecutionDegreeElem = (InfoExecutionDegree) arg0;
                if (infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getSigla().equals(
                        infoExecutionDegreeElem.getInfoDegreeCurricularPlan().getInfoDegree().getSigla())) {
                    return true;
                }
                return false;
            }
        });
        if (equalDegrees.size() == 1) {
            copyExecutionDegrees.remove(infoExecutionDegree);

            String degreeType = null;
            if (messageResources != null) {
                degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan()
                        .getInfoDegree().getDegreeType().toString());
            }
            if (degreeType == null) {
                degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType()
                        .toString();
            }

            result.add(new LabelValueBean(
                    degreeType + "  "
                            + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getNome(),
                    infoExecutionDegree.getExternalId().toString()));
        } else {
            String degreeType = null;
            if (messageResources != null) {
                degreeType = messageResources.getMessage(infoExecutionDegree.getInfoDegreeCurricularPlan()
                        .getInfoDegree().getDegreeType().toString());
            }
            if (degreeType == null) {
                degreeType = infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree().getDegreeType()
                        .toString();
            }

            result.add(
                    new LabelValueBean(
                            degreeType + "  "
                                    + infoExecutionDegree.getInfoDegreeCurricularPlan().getInfoDegree()
                                            .getNome()
                                    + " - " + infoExecutionDegree.getInfoDegreeCurricularPlan().getName(),
                            infoExecutionDegree.getExternalId().toString()));
        }
    }
    return result;

}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.mapping.CompassMappingUtils.java

/**
 * Resolve aliases between mappings//w w  w .j av a 2  s. c om
 * Note this method is destructive in the sense that it modifies the passed in mappings
 */
public static void resolveAliases(List classMappings, Collection grailsDomainClasses) {
    // set defaults for those classes without explicit aliases and collect aliases
    Map mappingByClass = new HashMap();
    Map mappingsByAlias = new HashMap();
    for (Iterator iter = classMappings.iterator(); iter.hasNext();) {
        CompassClassMapping classMapping = (CompassClassMapping) iter.next();
        if (classMapping.getAlias() == null) {
            classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass()));
        }
        mappingByClass.put(classMapping.getMappedClass(), classMapping);
        List mappings = (List) mappingsByAlias.get(classMapping.getAlias());
        if (mappings == null) {
            mappings = new ArrayList();
            mappingsByAlias.put(classMapping.getAlias(), mappings);
        }
        mappings.add(classMapping);
    }

    // override duplicate inherited aliases
    for (Iterator iter = mappingsByAlias.keySet().iterator(); iter.hasNext();) {
        List mappings = (List) mappingsByAlias.get(iter.next());
        if (mappings.size() == 1) {
            continue;
        }
        CompassClassMapping parentMapping = null;
        for (Iterator miter = mappings.iterator(); miter.hasNext();) {
            CompassClassMapping classMapping = (CompassClassMapping) miter.next();
            if (classMapping.getMappedClassSuperClass() == null) {
                parentMapping = classMapping;
                break;
            }
        }
        mappings.remove(parentMapping);
        for (Iterator miter = mappings.iterator(); miter.hasNext();) {
            CompassClassMapping classMapping = (CompassClassMapping) miter.next();
            LOG.debug("Overriding duplicated alias [" + classMapping.getAlias() + "] for class ["
                    + classMapping.getMappedClass().getName()
                    + "] with default alias. (Aliases must be unique - maybe this was inherited from a superclass?)");
            classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass()));
        }
    }

    // resolve property ref aliases
    for (Iterator iter = classMappings.iterator(); iter.hasNext();) {
        CompassClassMapping classMapping = (CompassClassMapping) iter.next();
        Class mappedClass = classMapping.getMappedClass();
        for (Iterator piter = classMapping.getPropertyMappings().iterator(); piter.hasNext();) {
            CompassClassPropertyMapping propertyMapping = (CompassClassPropertyMapping) piter.next();
            if ((propertyMapping.isComponent() || propertyMapping.isReference())
                    && !propertyMapping.hasAttribute("refAlias")) {
                Set aliases = new HashSet();
                Class clazz = propertyMapping.getPropertyType();
                aliases.add(((CompassClassMapping) mappingByClass.get(clazz)).getAlias());
                GrailsDomainClassProperty domainClassProperty = GrailsDomainClassUtils
                        .getGrailsDomainClassProperty(grailsDomainClasses, mappedClass,
                                propertyMapping.getPropertyName());
                Collection clazzes = GrailsDomainClassUtils
                        .getClazzes(domainClassProperty.getReferencedDomainClass().getSubClasses());
                for (Iterator citer = clazzes.iterator(); citer.hasNext();) {
                    CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(citer.next());
                    if (mapping != null) {
                        aliases.add(mapping.getAlias());
                    }
                }
                propertyMapping.setAttrbute("refAlias", DefaultGroovyMethods.join(aliases, ", "));
            }
        }
    }

    // resolve extend aliases
    for (Iterator iter = classMappings.iterator(); iter.hasNext();) {
        CompassClassMapping classMapping = (CompassClassMapping) iter.next();
        Class mappedClassSuperClass = classMapping.getMappedClassSuperClass();
        if (mappedClassSuperClass != null && classMapping.getExtend() == null) {
            CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(mappedClassSuperClass);
            classMapping.setExtend(mapping.getAlias());
        }
    }
}

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

public static void updateFieldParameters(TDashboardFieldBean field, Connection con) {
    List params = TDashboardParameterPeer.getByDashboardField(field.getObjectID(), con);
    Map mapParams = new HashMap();
    if (params != null) {
        for (Iterator it = params.iterator(); it.hasNext();) {
            TDashboardParameter param = (TDashboardParameter) it.next();
            if (param.getParamValue() != null) {
                mapParams.put(param.getName(), param.getParamValue());
            }//from   w  ww.  j a  va 2 s.  c o  m
        }
    }
    field.setParametres(mapParams);
}

From source file:com.facebook.LegacyTokenCacheTest.java

private static void assertListEquals(List<?> l1, List<?> l2) {
    assertNotNull(l1);/*from  ww w.j a  v  a 2  s  . c  om*/
    assertNotNull(l2);

    Iterator<?> i1 = l1.iterator(), i2 = l2.iterator();
    while (i1.hasNext() && i2.hasNext()) {
        assertEquals(i1.next(), i2.next());
    }

    assertTrue("Lists not of the same length", !i1.hasNext());
    assertTrue("Lists not of the same length", !i2.hasNext());
}

From source file:de.ingrid.portal.global.UtilsMapServiceManager.java

/**
 * Check for different classifications of a point
 * //from ww w.ja va2 s .  c o  m
 * @param value
 * @param coordClasses
 * @return if not in array return true
 */
public static Boolean checkExistingClassifications(String value, List<String> coordClasses) {
    Iterator<String> it = coordClasses.iterator();
    boolean found = false;

    while (it.hasNext() && !found) {
        if (it.next().equals(value)) {
            found = true;
        }
    }
    return found;
}

From source file:com.amalto.core.storage.hibernate.TypeMapping.java

protected static <T> void resetList(List<T> oldValues, List<T> newValues) {
    if (newValues == null) {
        if (oldValues != null) {
            oldValues.clear();/*from w w  w  .j  a va 2s.c o  m*/
        }
        return;
    }
    Iterator<T> iterator = newValues.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        T nextNew = iterator.next();
        if (nextNew != null) {
            if (i < oldValues.size() && !nextNew.equals(oldValues.get(i))) {
                oldValues.set(i, nextNew);
            } else if (i >= oldValues.size()) {
                oldValues.add(i, nextNew);
            }
        }
    }
    while (oldValues.size() > newValues.size()) {
        oldValues.remove(oldValues.size() - 1);
    }
}

From source file:com.spotify.heroic.HeroicShell.java

static void standalone(List<String> arguments, Builder builder) throws Exception {
    final String taskName = arguments.iterator().next();
    final List<String> rest = arguments.subList(1, arguments.size());

    log.info("Running standalone task {}", taskName);

    final HeroicCore core = builder.build();

    log.info("Starting Heroic...");
    final HeroicCoreInstance instance = core.newInstance();

    instance.start().get();//from   w  w w .  j a v a  2 s. c om

    final ShellTask task = instance.inject(c -> c.tasks().resolve(taskName));

    final TaskParameters params = task.params();

    final CmdLineParser parser = setupParser(params);

    try {
        parser.parseArgument(rest);
    } catch (CmdLineException e) {
        log.error("Error parsing arguments", e);
        System.exit(1);
        return;
    }

    if (params.help()) {
        parser.printUsage(System.err);
        HeroicModules.printAllUsage(System.err, "-P");
        System.exit(0);
        return;
    }

    try {
        final PrintWriter o = standaloneOutput(params, System.out);
        final ShellIO io = new DirectShellIO(o);

        try {
            task.run(io, params).get();
        } catch (Exception e) {
            log.error("Failed to run task", e);
        } finally {
            o.flush();
        }
    } finally {
        instance.shutdown().get();
    }
}

From source file:com.liangc.hq.base.utils.MonitorUtils.java

/**
 * Method findServiceTypes.// w w  w. j a  va 2 s  . co  m
 * 
 * Given a List of services associated with an application or server, 
 * filter through them for the  service types so we can link to showing 
 * selections by type. The returned List has the ServiceTypeValue as 
 * elements.
 * 
 * This should eventually get pushed into the bizapp
 * 
 * @param services
 * @return List
 */
public static List<ServiceTypeValue> findServiceTypes(List services, Boolean internal) {
    TreeMap<String, ServiceTypeValue> serviceTypeSet = new TreeMap<String, ServiceTypeValue>();
    for (Iterator i = services.iterator(); i.hasNext();) {
        AppdefResourceValue svcCandidate = (AppdefResourceValue) i.next();
        final AppdefEntityID aeid = svcCandidate.getEntityId();
        if (aeid.isService() || aeid.isGroup()) {
            AppdefResourceValue service = (AppdefResourceValue) svcCandidate;
            if (service != null && service.getAppdefResourceTypeValue() != null) {
                // if we don't have a group that is a compat group of services, then this
                // better throw a ClassCastException
                ServiceTypeValue svcType = (ServiceTypeValue) service.getAppdefResourceTypeValue();
                if (internal == null) {
                    // if we're not discriminating between internal and deployed, we'll just
                    // return them all
                    serviceTypeSet.put(svcType.getName(), svcType);
                } else if (internal != null && new Boolean(svcType.getIsInternal()).equals(internal)) {
                    serviceTypeSet.put(svcType.getName(), svcType);
                }
            }
        } else {
            throw new IllegalStateException("Did not get a valid service: " + svcCandidate);
        }
    }
    return new ArrayList(serviceTypeSet.values());
}

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 * Returns the font family names available through extensions, in alphabetical order.
 *///from w w w.  java2 s  .  com
public static Collection<String> getFontFamilyNames() {
    TreeSet<String> familyNames = new TreeSet<String>();//FIXMEFONT use collator for order?
    //FIXMEFONT do some cache
    List<FontFamily> families = ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class);
    for (Iterator<FontFamily> itf = families.iterator(); itf.hasNext();) {
        FontFamily family = itf.next();
        familyNames.add(family.getName());
    }
    return familyNames;
}

From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java

private static void removeNotYetImplemented(final List<String> lines, final int i, final String browserString) {
    final String previous = lines.get(i - 1);
    if (previous.contains("@NotYetImplemented")) {
        if (previous.indexOf('(') != -1) {
            final int p0 = previous.indexOf('(') + 1;
            final int p1 = previous.lastIndexOf(')');
            String browsers = previous.substring(p0, p1);
            if (browsers.indexOf('{') != -1) {
                browsers = browsers.substring(1, browsers.length() - 1).trim();
            }/*from  ww  w  . j a  va 2  s .  c om*/
            final Set<String> browserSet = new HashSet<>();
            for (final String browser : browsers.split(",")) {
                browserSet.add(browser.trim());
            }
            browserSet.remove(browserString);
            if (browserSet.size() == 1) {
                lines.set(i - 1, "    @NotYetImplemented(" + browserSet.iterator().next() + ")");
            } else if (browserSet.size() > 1) {
                lines.set(i - 1, "    @NotYetImplemented({ " + StringUtils.join(browserSet, ", ") + " })");
            } else {
                lines.remove(i - 1);
            }
        } else {
            final List<String> allBrowsers = new ArrayList<>(
                    Arrays.asList("CHROME", "IE11", "FF31", "FF38", "EDGE"));
            for (final Iterator<String> it = allBrowsers.iterator(); it.hasNext();) {
                if (it.next().equals(browserString)) {
                    it.remove();
                }
            }
            lines.set(i - 1, "    @NotYetImplemented({ " + StringUtils.join(allBrowsers, ", ") + " })");
        }
    }
}