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.uci.ics.hyracks.algebricks.rewriter.rules.FactorRedundantGroupAndDecorVarsRule.java

private boolean factorRedundantRhsVars(List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> veList,
        Mutable<ILogicalOperator> opRef, Map<LogicalVariable, LogicalVariable> varRhsToLhs,
        IOptimizationContext context) throws AlgebricksException {
    varRhsToLhs.clear();//from w  w  w .  j  a  v a  2 s  . com
    ListIterator<Pair<LogicalVariable, Mutable<ILogicalExpression>>> iter = veList.listIterator();
    boolean changed = false;
    while (iter.hasNext()) {
        Pair<LogicalVariable, Mutable<ILogicalExpression>> p = iter.next();
        if (p.second.getValue().getExpressionTag() != LogicalExpressionTag.VARIABLE) {
            continue;
        }
        LogicalVariable v = GroupByOperator.getDecorVariable(p);
        LogicalVariable lhs = varRhsToLhs.get(v);
        if (lhs != null) {
            if (p.first != null) {
                AssignOperator assign = new AssignOperator(p.first,
                        new MutableObject<ILogicalExpression>(new VariableReferenceExpression(lhs)));
                ILogicalOperator op = opRef.getValue();
                assign.getInputs().add(new MutableObject<ILogicalOperator>(op));
                opRef.setValue(assign);
                context.computeAndSetTypeEnvironmentForOperator(assign);
            }
            iter.remove();
            changed = true;
        } else {
            varRhsToLhs.put(v, p.first);
        }
    }
    return changed;
}

From source file:org.alfresco.repo.admin.patch.impl.AddUnmovableAspectToSitesPatch.java

@Override
protected String applyInternal() throws Exception {
    BatchProcessWorkProvider<ChildAssociationRef> workProvider = new BatchProcessWorkProvider<ChildAssociationRef>() {
        NodeRef sitesRoot = siteService.getSiteRoot();
        List<ChildAssociationRef> sites = nodeService.getChildAssocs(sitesRoot,
                Collections.singleton(SiteModel.TYPE_SITE));
        final Iterator<ChildAssociationRef> iterator = sites.listIterator();

        @Override/*w w  w . j  av a  2 s. co m*/
        public int getTotalEstimatedWorkSize() {
            return sites.size();
        }

        @Override
        public Collection<ChildAssociationRef> getNextWork() {
            List<ChildAssociationRef> sites = new ArrayList<ChildAssociationRef>(BATCH_SIZE);
            while (iterator.hasNext() && sites.size() <= BATCH_SIZE) {
                sites.add(iterator.next());
            }
            return sites;
        }
    };

    RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
    txnHelper.setForceWritable(true);

    BatchProcessor<ChildAssociationRef> batchProcessor = new BatchProcessor<ChildAssociationRef>(
            "AddUnmovableAspectToSitesPatch", txnHelper, workProvider, NUM_THREADS, BATCH_SIZE,
            applicationEventPublisher, logger, 1000);

    final String authenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
    BatchProcessor.BatchProcessWorker<ChildAssociationRef> worker = new BatchProcessor.BatchProcessWorker<ChildAssociationRef>() {
        public void afterProcess() throws Throwable {
        }

        public void beforeProcess() throws Throwable {
        }

        public String getIdentifier(ChildAssociationRef entry) {
            return entry.toString();
        }

        public void process(final ChildAssociationRef child) throws Throwable {
            /*
             * Fix for MNT-15064.
             * Run as authenticated user to make sure the nodes are searched in the correct space store.
             */
            RunAsWork<Void> work = new RunAsWork<Void>() {
                @Override
                public Void doWork() throws Exception {
                    try {
                        behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
                        nodeService.addAspect(child.getChildRef(), ContentModel.ASPECT_UNMOVABLE, null);
                    } finally {
                        behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
                    }
                    return null;
                }
            };
            AuthenticationUtil.runAs(work, authenticatedUser);
        }
    };

    batchProcessor.process(worker, true);

    return I18NUtil.getMessage(MSG_SUCCESS);
}

From source file:org.apache.syncope.console.pages.panels.AttributesPanel.java

private void filter(final List<SchemaTO> schemaTOs, final Set<String> allowed) {
    for (ListIterator<SchemaTO> itor = schemaTOs.listIterator(); itor.hasNext();) {
        SchemaTO schema = itor.next();//  w w  w  .  j  a v a  2s .c  om
        if (!allowed.contains(schema.getName())) {
            itor.remove();
        }
    }
}

From source file:com.dgtlrepublic.anitomyj.ParserHelper.java

/**
 * Builds an element an adds it to the internal element list.
 *
 * @param category       the element category
 * @param keepDelimiters delimiters to keep in the element content.
 * @param tokens         the tokens used to create the element content value.
 *//*w  w w. j  a va 2s .  com*/
public void buildElement(ElementCategory category, boolean keepDelimiters, List<Token> tokens) {
    StringBuilder element = new StringBuilder();

    for (ListIterator<Token> iter = tokens.listIterator(); iter.hasNext();) {
        Token token = iter.next();
        switch (token.getCategory()) {
        case kUnknown:
            element.append(token.getContent());
            token.setCategory(kIdentifier);
            break;
        case kBracket:
            element.append(token.getContent());
            break;
        case kDelimiter: {
            String delimiter = "";
            if (StringUtils.isNotEmpty(token.getContent())) {
                delimiter = StringUtils.substring(token.getContent(), 0, 1);
            }

            if (keepDelimiters) {
                element.append(delimiter);
            } else if (iter.hasPrevious() && iter.hasNext()) {
                switch (delimiter) {
                case ",":
                case "&":
                    element.append(delimiter);
                    break;
                default:
                    element.append(' ');
                    break;
                }
            }
            break;
        }
        }
    }

    if (!keepDelimiters) {
        element = new StringBuilder(StringHelper.trimAny(element.toString(), kDashesWithSpace));
    }

    if (!element.toString().isEmpty()) {
        parser.getElements().add(new Element(category, element.toString()));
    }
}

From source file:org.apache.fop.layoutmgr.table.ColumnSetup.java

private void prepareColumns() {
    List rawCols = table.getColumns();
    if (rawCols != null) {
        int colnum = 1;
        ListIterator iter = rawCols.listIterator();
        while (iter.hasNext()) {
            TableColumn col = (TableColumn) iter.next();
            if (col == null) {
                continue;
            }//from www. java 2  s. c  om
            colnum = col.getColumnNumber();
            for (int i = 0; i < col.getNumberColumnsRepeated(); i++) {
                while (colnum > columns.size()) {
                    columns.add(null);
                }
                columns.set(colnum - 1, col);
                colnum++;
            }
        }
        //Post-processing the list (looking for gaps)
        //TODO The following block could possibly be removed
        int pos = 1;
        ListIterator ppIter = columns.listIterator();
        while (ppIter.hasNext()) {
            TableColumn col = (TableColumn) ppIter.next();
            if (col == null) {
                assert false; //Gaps are filled earlier by fo.flow.table.Table.finalizeColumns()
                //log.error("Found a gap in the table-columns at position " + pos);
            }
            pos++;
        }
    }
}

From source file:com.krawler.esp.project.task.TaskCPMWithPERTImpl.java

private TaskCPM getTaskCPMValuesObject(Task task, List<TaskCPM> tasks) {
    Iterator ite = tasks.listIterator();
    while (ite.hasNext()) {
        TaskCPM temp = (TaskCPM) ite.next();
        if (temp.getTask().equals(task)) {
            return temp;
        }/*from  w  ww. ja  v a  2s.  c om*/
    }
    return null;
}

From source file:annis.visualizers.iframe.partitur.PartiturVisualizer.java

private boolean checkRTL(List<AnnisToken> tokenList) {
    Iterator<AnnisToken> itToken = tokenList.listIterator();
    while (itToken.hasNext()) {
        AnnisToken tok = itToken.next();
        String tokText = tok.getText();
        if (CommonHelper.containsRTLText(tokText)) {
            return true;
        }//w  ww  .  ja  v  a2  s .c om
    }

    return false;
}

From source file:com.alibaba.antx.config.resource.http.HttpResource.java

@Override
public List list() {
    if (isDirectory()) {
        String overridingCharset = getURI().getOption("charset");
        IndexPageParser[] parsers = new IndexPageParser[] { new SvnIndexPageParser(),
                new ApacheIndexPageParser(overridingCharset) };
        List items = null;

        for (IndexPageParser parser : parsers) {
            items = parser.parse(this);

            if (items != null) {
                break;
            }/*from  w w  w .  ja va2  s.  c  o  m*/
        }

        if (items != null) {
            for (ListIterator i = items.listIterator(); i.hasNext();) {
                IndexPageParser.Item item = (IndexPageParser.Item) i.next();
                Resource resource = new HttpResource((HttpSession) getSession(),
                        getURI().getSubURI(item.getName(), item.isDirectory()));

                i.set(resource);
            }
        }

        return items;
    }

    return null;
}

From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java

protected void processFileItemList(List<FileItem> fileItems, String media, String type)
        throws FileNotFoundException, IOException {
    File typeDir = getTypeDir(media, type, true);

    ListIterator<FileItem> fileItemIterator = fileItems.listIterator();
    while (fileItemIterator.hasNext()) {
        FileItem item = fileItemIterator.next();
        if (item.isFormField()) {
            fileItemIterator.remove();//from w w w.j  a  v a 2 s  .  c o m
        } else {
            File f = createFile(typeDir, item);
        }
    }
}

From source file:de.uhh.l2g.plugins.guest.OpenAccessVideos.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {
    String resourceID = resourceRequest.getResourceID();
    String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
    if (cmd.equals("get_search_words")) {
        getSearchWords(resourceRequest, resourceResponse);
    }/*from  w w w.j av  a  2s. co m*/

    try {
        if (resourceID.equals("showSegments")) {
            String vId = ParamUtil.getString(resourceRequest, "videoId");
            Long vID = new Long(vId);
            com.liferay.portal.kernel.json.JSONArray ja = JSONFactoryUtil.createJSONArray();
            //get segments for video and convert to json array
            try {
                List<Segment> sl = SegmentLocalServiceUtil.getSegmentsByVideoId(vID);
                ListIterator<Segment> sIt = sl.listIterator();
                while (sIt.hasNext()) {
                    Segment s = sIt.next();
                    JSONObject jo = JSONFactoryUtil.createJSONObject();
                    jo.put("chapter", s.getChapter());
                    jo.put("description", s.getDescription());
                    jo.put("end", s.getEnd());
                    jo.put("image", s.getImage());
                    jo.put("number", s.getNumber());
                    jo.put("segmentId", s.getPrimaryKey());
                    jo.put("seconds", s.getSeconds());
                    jo.put("start", s.getStart());
                    jo.put("title", s.getTitle());
                    jo.put("userId", s.getUserId());
                    jo.put("videoId", s.getVideoId());
                    jo.put("previousSegmentId", SegmentLocalServiceUtil.getPreviusSegmentId(s.getSegmentId()));
                    ja.put(jo);
                }

            } catch (PortalException e) {
                e.printStackTrace();
            } catch (SystemException e) {
                e.printStackTrace();
            }
            writeJSON(resourceRequest, resourceResponse, ja);
        }
    } catch (NullPointerException npe) {
    }

}