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:com.byraphaelmedeiros.autosubdown.AutoSubDown.java

private static String extractLink(String content) {
    LOGGER.log(Level.INFO, "Extracting URLs...");

    List<String> urls = extractUrls(content);

    if (!urls.isEmpty())
        return urls.iterator().next();

    return null;// w  ww  .  ja v a  2  s . c  o m
}

From source file:Main.java

/**
 * Appends the specified path token to the provided buffer
 * followed by the position specification of the target node in
 * its siblings list.// w  w  w. ja  va 2s . c  o m
 *
 * @param  node        the target node for the XPath expression.
 * @param  siblings    the siblings of the target node.
 * @param  pathToken   the path token identifying the target node.
 * @param  buffer      the buffer to which appending the XPath
 *                     sub-expression or <code>null</code> if the
 *                     method shall allocate a new buffer.
 *
 * @return the XPath sub-expression to select the target node
 *         among its siblings.
 */
private static StringBuilder getPositionPath(Object node, List<?> siblings, String pathToken,
        StringBuilder buffer) {
    if (buffer == null) {
        buffer = new StringBuilder();
    }
    if (pathToken != null) {
        buffer.append(pathToken);
    }

    if ((siblings != null) && (siblings.size() != 1)) {
        int position = 0;
        for (Iterator<?> i = siblings.iterator(); i.hasNext();) {
            position++;
            if (i.next() == node)
                break;
        }
        buffer.append('[').append(position).append(']');
    }
    return buffer;
}

From source file:info.magnolia.importexport.BootstrapUtil.java

public static void bootstrap(String[] resourceNames, int importUUIDBehavior)
        throws IOException, RepositoryException {
    // sort by length --> import parent node first
    List<String> list = new ArrayList<String>(Arrays.asList(resourceNames));

    Collections.sort(list, new StringLengthComparator());

    for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
        String resourceName = iter.next();

        String name = getFilenameFromResource(resourceName, ".xml");
        String repository = getWorkspaceNameFromResource(resourceName);
        String pathName = getPathnameFromResource(resourceName);
        String fullPath = getFullpathFromResource(resourceName);
        String nodeName = StringUtils.substringAfterLast(fullPath, "/");

        log.debug("Will bootstrap {}", resourceName);

        final InputStream stream = BootstrapUtil.class.getResourceAsStream(resourceName);
        if (stream == null) {
            throw new IOException("Can't find resource to bootstrap at " + resourceName);
        }//  w  w w  .  j a  v a 2  s. co  m

        // if the node already exists we will keep the order
        String nameOfNodeAfterTheImportedNode = null;

        final HierarchyManager hm = MgnlContext.getHierarchyManager(repository);

        // if the path already exists --> delete it
        try {

            // HM can be null if module is not properly registered and the repository has not been created
            if (hm != null && hm.isExist(fullPath)) {
                // but keep the order
                Content node = hm.getContent(fullPath);
                SiblingsHelper siblings = SiblingsHelper.of(node);
                if (!siblings.isLast()) {
                    nameOfNodeAfterTheImportedNode = siblings.next().getName();
                }

                hm.delete(fullPath);
                log.warn("Deleted already existing node for bootstrapping: {}", fullPath);
            }
        } catch (RepositoryException e) {
            throw new RepositoryException("Can't check existence of node for bootstrap file: [" + name + "]",
                    e);
        }

        DataTransporter.importXmlStream(stream, repository, pathName, name, false, importUUIDBehavior, false,
                true);

        if (nameOfNodeAfterTheImportedNode != null) {
            Content newNode = hm.getContent(fullPath);
            newNode.getParent().orderBefore(nodeName, nameOfNodeAfterTheImportedNode);
        }

    }
}

From source file:com.evilisn.DAO.CertMapper.java

static URI getIssuerCertURL(X509CertImpl var0) {
    AuthorityInfoAccessExtension var1 = var0.getAuthorityInfoAccessExtension();
    if (var1 == null) {
        return null;
    } else {/*  w  w  w  .  j av a  2s. c om*/
        List var2 = var1.getAccessDescriptions();
        Iterator var3 = var2.iterator();

        while (var3.hasNext()) {
            AccessDescription var4 = (AccessDescription) var3.next();
            if (var4.getAccessMethod().equals(AccessDescription.Ad_CAISSUERS_Id)) {
                GeneralName var5 = var4.getAccessLocation();
                if (var5.getType() == 6) {
                    URIName var6 = (URIName) var5.getName();
                    return var6.getURI();
                }
            }
        }

        return null;
    }
}

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

public static List<IField> loadFullChildren(Integer objectID, Connection con) throws TorqueException {
    Criteria critChild = new Criteria();
    critChild.add(BaseTScreenFieldPeer.PARENT, objectID);
    List<IField> result = new ArrayList<IField>();
    List torqueList = BaseTScreenFieldPeer.doSelect(critChild, con);
    if (torqueList != null) {
        Iterator itrTorqueList = torqueList.iterator();
        while (itrTorqueList.hasNext()) {
            result.add(((TScreenField) itrTorqueList.next()).getBean());
        }//from  w ww .j  ava2  s.c o m
    }
    return result;
}

From source file:com.github.pmerienne.cf.testing.dataset.DatasetUtils.java

public static List<Rating> extractEval(List<Rating> ratings, double trainingPercent) {
    int evalSize = (int) (ratings.size() * (1.0 - trainingPercent));
    List<Rating> eval = new ArrayList<>(evalSize);

    Set<Long> knownUsers = new HashSet<>();
    Set<Long> knownItems = new HashSet<>();

    Iterator<Rating> it = ratings.iterator();
    while (it.hasNext() && eval.size() < evalSize) {
        Rating rating = it.next();//from ww  w  .  j  a  v  a  2s . c  o  m

        if (knownUsers.contains(rating.i) && knownItems.contains(rating.j)) {
            eval.add(rating);
            it.remove();
        }
        knownUsers.add(rating.i);
        knownItems.add(rating.j);
    }

    return eval;
}

From source file:com.aurel.track.admin.customize.lists.importList.ImportListBL.java

/**
 * Load the list hierarchy from the database which will be updated
 * @param globalList//from   w  w  w  . j av  a2s .  c  o m
 * @return
 */
public static List<TListBean> loadHierarchy(TListBean globalList) {
    List<TListBean> list = new ArrayList<TListBean>();
    List<TListBean> queue = new ArrayList<TListBean>();
    if (ListBL.loadByPrimaryKey(globalList.getObjectID()) != null) {
        list.add(globalList);
        queue.add(globalList);
        do {
            List<TListBean> childList = ListBL.getChildLists(queue.get(0).getObjectID());
            queue.remove(0);

            Iterator itr = childList.iterator();
            while (itr.hasNext()) {
                TListBean tmpListBean = (TListBean) itr.next();
                list.add(tmpListBean);
                queue.add(tmpListBean);
            }
        } while (queue.size() != 0);
    }
    return list;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.teachersBody.ReadProfessorshipsAndResponsibilitiesByDepartmentAndExecutionPeriod.java

@Atomic
public static List run(String departmentId, String executionYearID, Integer semester, Integer teacherType)
        throws FenixServiceException {

    ExecutionYear executionYear = null;/*  www .j a  va 2 s .com*/
    if (executionYearID != null) {
        executionYear = FenixFramework.getDomainObject(executionYearID);
    }

    final ExecutionSemester executionSemester = executionYear.getExecutionSemesterFor(semester);
    if (semester.intValue() != 0 && executionSemester == null) {
        throw new FenixServiceException("error.noExecutionPeriod");
    }

    final Department department = FenixFramework.getDomainObject(departmentId);
    if (department == null) {
        throw new FenixServiceException("error.noDepartment");
    }

    final List<Teacher> teachers = department.getAllCurrentTeachers();

    Iterator iter = teachers.iterator();

    List professorships = new ArrayList();
    List responsibleFors = new ArrayList();
    while (iter.hasNext()) {
        Teacher teacher = (Teacher) iter.next();
        Collection teacherProfessorships = null;
        if (executionYear == null) {
            teacherProfessorships = teacher.getProfessorships();
        } else {
            if (semester.intValue() == 0) {
                teacherProfessorships = teacher.getProfessorships(executionYear);
            } else {
                teacherProfessorships = teacher.getProfessorships(executionSemester);
            }
        }
        if (teacherProfessorships != null) {
            professorships.addAll(teacherProfessorships);
        }

        List teacherResponsibleFors;
        List<Professorship> teacherResponsibleForsAux = null;

        if (executionYear == null) {
            teacherResponsibleFors = teacher.responsibleFors();
        } else {
            teacherResponsibleForsAux = teacher.responsibleFors();
            teacherResponsibleFors = new ArrayList<Professorship>();
            for (Professorship professorship : teacherResponsibleForsAux) {
                if (professorship.getExecutionCourse().getExecutionPeriod().getExecutionYear()
                        .equals(executionYear)) {
                    teacherResponsibleFors.add(professorship);
                }
            }
        }
        if (teacherResponsibleFors != null) {
            responsibleFors.addAll(teacherResponsibleFors);
        }
    }

    List detailedProfessorships = getDetailedProfessorships(professorships, responsibleFors, teacherType);

    // Cleaning out possible null elements inside the list
    Iterator itera = detailedProfessorships.iterator();
    while (itera.hasNext()) {
        Object dp = itera.next();
        if (dp == null) {
            itera.remove();
        }
    }

    Collections.sort(detailedProfessorships, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {

            DetailedProfessorship detailedProfessorship1 = (DetailedProfessorship) o1;
            DetailedProfessorship detailedProfessorship2 = (DetailedProfessorship) o2;
            int result = detailedProfessorship1.getInfoProfessorship().getInfoExecutionCourse().getExternalId()
                    .compareTo(detailedProfessorship2.getInfoProfessorship().getInfoExecutionCourse()
                            .getExternalId());
            if (result == 0 && (detailedProfessorship1.getResponsibleFor().booleanValue()
                    || detailedProfessorship2.getResponsibleFor().booleanValue())) {
                if (detailedProfessorship1.getResponsibleFor().booleanValue()) {
                    return -1;
                }
                if (detailedProfessorship2.getResponsibleFor().booleanValue()) {
                    return 1;
                }
            }

            return result;
        }

    });

    List result = new ArrayList();
    iter = detailedProfessorships.iterator();
    List temp = new ArrayList();
    while (iter.hasNext()) {
        DetailedProfessorship detailedProfessorship = (DetailedProfessorship) iter.next();
        if (temp.isEmpty() || ((DetailedProfessorship) temp.get(temp.size() - 1)).getInfoProfessorship()
                .getInfoExecutionCourse()
                .equals(detailedProfessorship.getInfoProfessorship().getInfoExecutionCourse())) {
            temp.add(detailedProfessorship);
        } else {
            result.add(temp);
            temp = new ArrayList();
            temp.add(detailedProfessorship);
        }
    }
    if (!temp.isEmpty()) {
        result.add(temp);
    }
    return result;
}

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

private static int addExpectation(final List<String> lines, int i, final String browserString,
        final ComparisonFailure comparisonFailure) {
    while (!lines.get(i).startsWith("    @Alerts")) {
        i--;//from   w  w w  .  ja  va 2s  .  c  o m
    }
    final List<String> alerts = CodeStyleTest.alertsToList(lines, i);
    for (final Iterator<String> it = alerts.iterator(); it.hasNext();) {
        if (it.next().startsWith(browserString + " = ")) {
            it.remove();
        }
    }
    alerts.add(browserString + " = " + getActualString(comparisonFailure));
    lines.remove(i);
    while (lines.get(i).startsWith("        ")) {
        lines.remove(i);
    }
    for (int x = 0; x < alerts.size(); x++) {
        String line = alerts.get(x);
        if (x == 0) {
            if (!line.contains(" = ")) {
                line = "DEFAULT = " + line;
            }
            line = "    @Alerts(" + line;
        } else {
            line = "            " + line;
        }
        if (x < alerts.size() - 1) {
            line += ",";
        } else {
            line += ")";
        }
        lines.add(i++, line);
    }
    return i;
}

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

private static List convertTorqueListToBeanList(List torqueList) {
    List beanList = new ArrayList();
    if (torqueList != null) {
        Iterator itrTorqueList = torqueList.iterator();
        while (itrTorqueList.hasNext()) {
            beanList.add(((TMSProjectTask) itrTorqueList.next()).getBean());
        }//  www . j  a  va 2s. c o m
    }
    return beanList;
}