Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

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

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.SelectListGenerator.java

private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
        List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited) {
    log.debug(//from  w w  w.j a  v  a2 s .c o m
            "starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ...");
    HashSet<String> range = new HashSet<String>();

    for (ObjectPropertyStatement ops : stmts) {
        if (ops.getPropertyURI().equals(predicateUri))
            range.add(ops.getObjectURI());
    }

    int removeCount = 0;
    ListIterator<Individual> it = individuals.listIterator();
    while (it.hasNext()) {
        Individual ind = it.next();
        if (range.contains(ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited))) {
            it.remove();
            ++removeCount;
        }
    }
    log.debug("removed " + removeCount + " duplicate range individuals");
    return individuals;
}

From source file:com.espertech.esper.epl.core.ResultSetProcessorFactory.java

private static void expandColumnNames(List<SelectClauseElementCompiled> selectionList,
        List<OrderByItem> orderByList) {
    for (SelectClauseElementCompiled selectElement : selectionList) {
        // process only expressions
        if (!(selectElement instanceof SelectClauseExprCompiledSpec)) {
            continue;
        }/*  ww  w. jav a 2 s  .  c  o m*/
        SelectClauseExprCompiledSpec selectExpr = (SelectClauseExprCompiledSpec) selectElement;

        String name = selectExpr.getAssignedName();
        if (name != null) {
            ExprNode fullExpr = selectExpr.getSelectExpression();
            for (ListIterator<OrderByItem> iterator = orderByList.listIterator(); iterator.hasNext();) {
                OrderByItem orderByElement = iterator.next();
                ExprNode swapped = ColumnNamedNodeSwapper.swap(orderByElement.getExprNode(), name, fullExpr);
                OrderByItem newOrderByElement = new OrderByItem(swapped, orderByElement.isDescending());
                iterator.set(newOrderByElement);
            }
        }
    }
}

From source file:RedundancyChecker.java

public boolean checkForRedundancy(List l) {
    ListIterator li1 = l.listIterator(); // Make a
    // general/*from w  w w .j  ava 2s  . c  o m*/
    // ListIterator
    // on the list

    while (li1.hasNext()) {
        // Store the value of the actual first checked
        // element of the List,
        // it needs to be stored because it calls the
        // .next(), which we can call only once per loop
        // in order to sweep the whole list.
        int check1 = ((Integer) li1.next()).intValue();

        // Make a second ListIterator that will start
        // with the element that is just after the
        // actual first checked one,
        // in order to avoid checking several times the
        // same elements.
        ListIterator li2 = l.listIterator(li1.nextIndex() + 1);

        while (li2.hasNext()) {
            // Store the following elements one by
            // one and check to see if they match
            // the actual one.
            int check2 = ((Integer) li2.next()).intValue();
            if (check1 == check2) {
                System.out.println("Oh no! The value " + check1 + " is redundant.");
                return true;
            }
        }
        // The .next() method has already been called at
        // the beginning of the loop.
    }
    return false;
}

From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java

/**
 * Returns {@code true} if and only if the value starts with the supplied prefix.
 *
 * @param value  the value.//w  ww .  j  a  v  a  2s  .com
 * @param prefix the candidate prefix.
 * @return {@code true} if and only if the value starts with the supplied prefix.
 */
static boolean startsWith(@NonNull List<String> value, @NonNull List<String> prefix) {
    if (value.size() < prefix.size()) {
        return false;
    }
    ListIterator<String> i1 = value.listIterator();
    ListIterator<String> i2 = prefix.listIterator();
    while (i1.hasNext() && i2.hasNext()) {
        if (!i1.next().equals(i2.next())) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.fop.layoutmgr.SpaceResolver.java

/**
 * Resolves unresolved elements applying the space resolution rules defined in 4.3.1.
 * @param elems the element list//from www . j  a  v  a 2  s.  c om
 */
public static void resolveElementList(List elems) {
    if (LOG.isTraceEnabled()) {
        LOG.trace(elems);
    }
    boolean first = true;
    boolean last = false;
    boolean skipNextElement = false;
    List unresolvedFirst = new java.util.ArrayList();
    List unresolvedSecond = new java.util.ArrayList();
    List currentGroup;
    ListIterator iter = elems.listIterator();
    while (iter.hasNext()) {
        ListElement el = (ListElement) iter.next();
        if (el.isUnresolvedElement()) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("unresolved found: " + el + " " + first + "/" + last);
            }
            BreakElement breakPoss = null;
            //Clear temp lists
            unresolvedFirst.clear();
            unresolvedSecond.clear();
            //Collect groups
            if (el instanceof BreakElement) {
                breakPoss = (BreakElement) el;
                currentGroup = unresolvedSecond;
            } else {
                currentGroup = unresolvedFirst;
                currentGroup.add(el);
            }
            iter.remove();
            last = true;
            skipNextElement = true;
            while (iter.hasNext()) {
                el = (ListElement) iter.next();
                if (el instanceof BreakElement && breakPoss != null) {
                    skipNextElement = false;
                    last = false;
                    break;
                } else if (currentGroup == unresolvedFirst && (el instanceof BreakElement)) {
                    breakPoss = (BreakElement) el;
                    iter.remove();
                    currentGroup = unresolvedSecond;
                } else if (el.isUnresolvedElement()) {
                    currentGroup.add(el);
                    iter.remove();
                } else {
                    last = false;
                    break;
                }
            }
            //last = !iter.hasNext();
            if (breakPoss == null && unresolvedSecond.isEmpty() && !last) {
                LOG.trace("Swap first and second parts in no-break condition," + " second part is empty.");
                //The first list is reversed, so swap if this shouldn't happen
                List swapList = unresolvedSecond;
                unresolvedSecond = unresolvedFirst;
                unresolvedFirst = swapList;
            }

            LOG.debug("----start space resolution (first=" + first + ", last=" + last + ")...");
            SpaceResolver resolver = new SpaceResolver(unresolvedFirst, breakPoss, unresolvedSecond, first,
                    last);
            if (!last) {
                iter.previous();
            }
            resolver.generate(iter);
            if (!last && skipNextElement) {
                iter.next();
            }
            LOG.debug("----end space resolution.");
        }
        first = false;
    }
}

From source file:com.projity.grouping.core.hierarchy.MutableNodeHierarchy.java

private static Node[] addDescendants(List nodes) {
    ArrayList descendants = new ArrayList();
    for (ListIterator i = nodes.listIterator(); i.hasNext();) {
        Node node = (Node) i.next();
        extractSameProjectBranch(node, descendants);
        //             boolean rootNode=true;
        //           for (Enumeration e=((NodeBridge)node).preorderEnumeration();e.hasMoreElements();rootNode=false){
        //              Node current=(Node)e.nextElement();
        //              if (!rootNode) descendants.add(current);
        //           }
    }/*  ww w  . j ava  2s . c  om*/
    Node[] descendantsArray = (Node[]) descendants.toArray(new Node[descendants.size()]);
    return descendantsArray;
}

From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java

/**
 * Returns {@code true} if and only if the value starts with the supplied prefix.
 *
 * @param value          the value.//  ww w  .  j a  v a2s .c o m
 * @param wildcardPrefix the candidate prefix.
 * @return {@code true} if and only if the value starts with the supplied prefix.
 */
static boolean wildcardStartsWith(@NonNull List<String> value, @NonNull List<String> wildcardPrefix) {
    if (value.size() < wildcardPrefix.size()) {
        return false;
    }
    ListIterator<String> i1 = value.listIterator();
    ListIterator<String> i2 = wildcardPrefix.listIterator();
    while (i1.hasNext() && i2.hasNext()) {
        if (!isMatch(i1.next(), i2.next())) {
            return false;
        }
    }
    return true;
}

From source file:it.eng.spagobi.commons.presentation.tags.ListBIParametersTag.java

/**
 * Starting from the module <code>buttonsSB</code> object, 
 * creates all buttons for the jsp list. 
 * /*from  w w w .  ja  va 2  s  .com*/
 * @throws JspException If any exception occurs.
 */

protected StringBuffer makeButton() throws JspException {

    StringBuffer htmlStream = new StringBuffer();
    SourceBean buttonsSB = (SourceBean) _layout.getAttribute("BUTTONS");
    List buttons = buttonsSB.getContainedSourceBeanAttributes();
    Iterator iter = buttons.listIterator();
    while (iter.hasNext()) {
        SourceBeanAttribute buttonSBA = (SourceBeanAttribute) iter.next();
        SourceBean buttonSB = (SourceBean) buttonSBA.getValue();
        List parameters = buttonSB.getAttributeAsList("PARAMETER");
        HashMap paramsMap = getParametersMap(parameters, null);
        String img = (String) buttonSB.getAttribute("image");
        String labelCode = (String) buttonSB.getAttribute("label");
        String label = msgBuilder.getMessage(labelCode, "messages", httpRequest);
        label = StringEscapeUtils.escapeHtml(label);
        htmlStream.append("<form action='" + urlBuilder.getUrl(httpRequest, new HashMap()) + "' id='form"
                + label + "'  method='POST' >\n");
        htmlStream.append("   <td class=\"header-button-column-portlet-section\">\n");
        Set paramsKeys = paramsMap.keySet();
        Iterator iterpar = paramsKeys.iterator();
        while (iterpar.hasNext()) {
            String paramKey = (String) iterpar.next();
            String paramValue = (String) paramsMap.get(paramKey);
            while (paramValue.indexOf("%20") != -1) {
                paramValue = paramValue.replaceAll("%20", " ");
            }
            htmlStream.append(
                    "     <input type='hidden' name='" + paramKey + "' value='" + paramValue + "' /> \n");
        }
        htmlStream.append("      <a href='javascript:document.getElementById(\"form" + label
                + "\").submit()'><img class=\"header-button-image-portlet-section\" title='" + label + "' alt='"
                + label + "' src='" + urlBuilder.getResourceLinkByTheme(httpRequest, img, currTheme)
                + "' /></a>\n");
        htmlStream.append("   </td>\n");
        htmlStream.append("</form>\n");
    }
    return htmlStream;
}

From source file:net.duckling.ddl.service.mobile.ios.IOSMessageSender.java

private void dealNotice(List<PushedNotification> notice, IOSMessageBean bean) {
    ListIterator<PushedNotification> it = notice.listIterator();
    while (it.hasNext()) {
        PushedNotification no = it.next();
        if (!no.isSuccessful()) {
            LOG.error("send message " + bean + " error!", no.getException());
        }// ww w. ja  v a 2 s .c o  m
    }
}

From source file:org.consultjr.mvc.service.UserSystemProfileService.java

@Transactional
public List<String> getRolesOfUser(int userID) {
    List<SystemProfile> list = uspDAO.getSystemProfilesOfUser(userID);
    Iterator<SystemProfile> it = list.listIterator();
    List<String> roles = new ArrayList<>();
    while (it.hasNext()) {
        SystemProfile sp = it.next();/*  w ww  .  ja v  a2  s  .co m*/
        roles.add(sp.getShortname());
    }
    return roles;
}