Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

In this page you can find the example usage for java.util ListIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:com.krawler.esp.utils.ConfigReader.java

private synchronized Properties getProps() {
    if (properties == null) {
        Properties defaults = new Properties();
        Properties newProps = new Properties(defaults);
        ListIterator i = resourceNames.listIterator();
        while (i.hasNext()) {
            if (i.nextIndex() == 0) { // load defaults
                loadResource(defaults, i.next(), false);
            } else if (i.nextIndex() == resourceNames.size() - 1) { // load
                // site
                loadResource(newProps, i.next(), true);
            } else { // load intermediate
                loadResource(newProps, i.next(), false);
            }//w w w . j av  a  2 s  . co  m
        }
        properties = newProps;
    }
    return properties;
}

From source file:org.reunionemu.jreunion.server.Command.java

public void GoToPos(Player player, Position position) {
    Client client = player.getClient();/*from   www  . j a va2  s.c  om*/

    SessionList<Session> exit = player.getInterested().getSessions();
    exit.exit(player);

    SessionList<Session> entry = player.getPosition().getLocalMap().GetSessions(position);

    player.setPosition(position);

    ListIterator<Session> newSession = entry.listIterator();
    while (newSession.hasNext()) {
        Session newSessionObj = newSession.next();

        if (!newSessionObj.getOwner().equals(player)) {
            newSessionObj.enter(player, false);
            newSessionObj.getOwner().getClient().sendPacket(Type.IN_CHAR, player, true);
        }
    }
    player.update();
    client.sendPacket(Type.GOTO, position);
}

From source file:com.yahoo.semsearch.fastlinking.DPSearch.java

/**
 * Run forward-backward algorithm on multiple entity candidates and returns a filtered list of coherent entities
 * Takes nbest list and/*  w w w  .  j ava 2  s. com*/
 * @param nBestList an array of arraylists of wiki entities; for each entity span we have a list of candidate
 *                       wikilinks (nbest list)
 * @param entitySurfaceForms an array of entity spans
 * @return DPSearch object that contains lattice of paths and likelihood scores
 */
public DPSearch dynamicProgrammingSearch(List<String>[] nBestList, String[] entitySurfaceForms) {

    int sequenceLength = entitySurfaceForms.length;
    int nBestLength = MAXNBEST;
    double[][] logSimilarityOverall = new double[sequenceLength][nBestLength];
    for (int i = 0; i < logSimilarityOverall.length; i++) {
        Arrays.fill(logSimilarityOverall[i], DEFAULT_LOG_LIKELIHOOD);
    }
    String[][] path = new String[sequenceLength][nBestLength];
    for (int i = 0; i < path.length; i++) {
        Arrays.fill(path[i], "");
    }
    ListIterator<String> it = nBestList[0].listIterator();
    while (it.hasNext()) {
        //MAKE SURE to call NextIndex before Next

        int index = it.nextIndex();
        String currentCandidate = it.next();

        double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                entitySurfaceForms[0].replace(" ", "_"));
        double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                entitySurfaceForms[0]);

        logSimilarityOverall[0][index] = Math.max(
                Math.log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim),
                DEFAULT_LOG_LIKELIHOOD);

        path[0][index] = currentCandidate;
    }

    ListIterator<String> currentCandidateIterator, previousCandidateIterator;
    for (int i = 1; i < sequenceLength; i++) {
        currentCandidateIterator = nBestList[i].listIterator();

        while (currentCandidateIterator.hasNext()) {

            //MAKE SURE to call NextIndex before Next
            int currentCandidateIndex = currentCandidateIterator.nextIndex();
            String currentCandidate = currentCandidateIterator.next();

            double entity2WordSim = gensimEntityEmbeddings.entity2WordSimilarity(prependWiki(currentCandidate),
                    entitySurfaceForms[i].replace(" ", "_"));
            double lexicalSim = gensimEntityEmbeddings.lexicalSimilarity(currentCandidate.replace("_", " "),
                    entitySurfaceForms[i]);

            double candidateNBestSimilarity = Math
                    .log((1 - LEXSIM_LAMBDA) * entity2WordSim + LEXSIM_LAMBDA * lexicalSim);

            double bestSimilarity = 0.0;
            double interCandidateSimilarity = 0.0;
            int previousBestCandidateIndex = -1;
            previousCandidateIterator = nBestList[i - 1].listIterator();
            while (previousCandidateIterator.hasNext()) {

                //MAKE SURE to call NextIndex before Next

                int index = previousCandidateIterator.nextIndex();
                String previousCandidate = previousCandidateIterator.next();

                double entity2EntitySimilarity = gensimEntityEmbeddings
                        .entity2EntitySimilarity(prependWiki(previousCandidate), prependWiki(currentCandidate));

                double entity2EntityLexicalSimilarity = gensimEntityEmbeddings.lexicalSimilarity(
                        previousCandidate.replace("_", " "), currentCandidate.replace("_", " "));

                double jointSimilarity = (1 - LEXSIM_LAMBDA) * entity2EntitySimilarity
                        + LEXSIM_LAMBDA * entity2EntityLexicalSimilarity;
                interCandidateSimilarity = Math.log(jointSimilarity);

                if (bestSimilarity == 0.0) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                } else if (interCandidateSimilarity + logSimilarityOverall[i - 1][index] > bestSimilarity) {
                    bestSimilarity = interCandidateSimilarity + logSimilarityOverall[i - 1][index];
                    previousBestCandidateIndex = index;

                }
            }
            try {
                logSimilarityOverall[i][currentCandidateIndex] = Math
                        .max(bestSimilarity + candidateNBestSimilarity, DEFAULT_LOG_LIKELIHOOD);

                path[i][currentCandidateIndex] = path[i - 1][previousBestCandidateIndex] + CANDIDATE_DELIMITER
                        + currentCandidate;

            } catch (ArrayIndexOutOfBoundsException e) {
                e.getMessage();
            }
        }

    }
    RealVector realVector = new ArrayRealVector(logSimilarityOverall[sequenceLength - 1]);
    int bestPathIndex = realVector.getMaxIndex();

    DPSearch dpSearch = new DPSearch(logSimilarityOverall, path);
    return dpSearch;
}

From source file:umontreal.iro.lecuyer.charts.HistogramChart.java

/**
 * Synchronizes <SPAN CLASS="MATH"><I>x</I></SPAN>-axis ticks to the <SPAN CLASS="MATH"><I>s</I></SPAN>-th histogram bins.
 * /*  ww  w  .  java2s. com*/
 * @param s selects histogram used to define ticks.
 * 
 * 
 */
public void setTicksSynchro(int s) {
    if (((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s) == -1) {
        DoubleArrayList newTicks = new DoubleArrayList();
        ListIterator binsIter = ((HistogramSeriesCollection) this.dataset).getBins(s).listIterator();

        int i = 0;
        HistogramBin prec = (HistogramBin) binsIter.next();
        double var;
        newTicks.add(prec.getStartBoundary());
        newTicks.add(var = prec.getEndBoundary());
        HistogramBin temp;
        while (binsIter.hasNext()) {
            temp = (HistogramBin) binsIter.next();
            if (temp.getStartBoundary() != var) {
                newTicks.add(var = temp.getStartBoundary());
            } else if (temp.getEndBoundary() != var) {
                newTicks.add(var = temp.getEndBoundary());
            }
        }
        XAxis.setLabels(newTicks.elements());
    } else {
        XAxis.setLabels(((CustomHistogramDataset) this.dataset.getSeriesCollection()).getBinWidth(s));
    }
}

From source file:com.google.gwt.emultest.java.util.ListTestBase.java

public void testListIteratorAddInSeveralPositions() {
    List l = makeEmptyList();//from w ww.  j a  va  2s.  co m
    ListIterator i = l.listIterator();
    l.add(new Integer(0));
    for (int n = 2; n < 5; n += 2) {
        l.add(new Integer(n));
    }
    i = l.listIterator();
    i.next();
    i.add(new Integer(1));
    i.next();
    i.next();
    i.previous();
    i.add(new Integer(3));
    i.next();
    i.add(new Integer(5));
    i.add(new Integer(6));
    for (int n = 0; n < 6; n++) {
        assertEquals(new Integer(n), l.get(n));
    }
}

From source file:com.opengamma.elsql.ElSqlParser.java

private void parseContainerSection(ContainerSqlFragment container, ListIterator<Line> lineIterator,
        int indent) {
    while (lineIterator.hasNext()) {
        Line line = lineIterator.next();
        if (line.isComment()) {
            lineIterator.remove();/*from   w w w .  jav  a2 s.c o m*/
            continue;
        }
        if (line.indent() <= indent) {
            lineIterator.previous();
            return;
        }
        String trimmed = line.lineTrimmed();
        if (trimmed.startsWith("@NAME")) {
            Matcher nameMatcher = NAME_PATTERN.matcher(trimmed);
            if (nameMatcher.matches() == false) {
                throw new IllegalArgumentException("@NAME found with invalid format: " + line);
            }
            NameSqlFragment nameFragment = new NameSqlFragment(nameMatcher.group(1));
            parseContainerSection(nameFragment, lineIterator, line.indent());
            if (nameFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@NAME found with no subsequent indented lines: " + line);
            }
            container.addFragment(nameFragment);
            _namedFragments.put(nameFragment.getName(), nameFragment);

        } else if (indent < 0) {
            throw new IllegalArgumentException(
                    "Invalid fragment found at root level, only @NAME is permitted: " + line);

        } else if (trimmed.startsWith("@PAGING")) {
            Matcher pagingMatcher = PAGING_PATTERN.matcher(trimmed);
            if (pagingMatcher.matches() == false) {
                throw new IllegalArgumentException("@PAGING found with invalid format: " + line);
            }
            PagingSqlFragment whereFragment = new PagingSqlFragment(pagingMatcher.group(1),
                    pagingMatcher.group(2));
            parseContainerSection(whereFragment, lineIterator, line.indent());
            if (whereFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@PAGING found with no subsequent indented lines: " + line);
            }
            container.addFragment(whereFragment);

        } else if (trimmed.startsWith("@WHERE")) {
            if (trimmed.equals("@WHERE") == false) {
                throw new IllegalArgumentException("@WHERE found with invalid format: " + line);
            }
            WhereSqlFragment whereFragment = new WhereSqlFragment();
            parseContainerSection(whereFragment, lineIterator, line.indent());
            if (whereFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@WHERE found with no subsequent indented lines: " + line);
            }
            container.addFragment(whereFragment);

        } else if (trimmed.startsWith("@AND")) {
            Matcher andMatcher = AND_PATTERN.matcher(trimmed);
            if (andMatcher.matches() == false) {
                throw new IllegalArgumentException("@AND found with invalid format: " + line);
            }
            AndSqlFragment andFragment = new AndSqlFragment(andMatcher.group(1),
                    StringUtils.strip(andMatcher.group(2), " ="));
            parseContainerSection(andFragment, lineIterator, line.indent());
            if (andFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@AND found with no subsequent indented lines: " + line);
            }
            container.addFragment(andFragment);

        } else if (trimmed.startsWith("@OR")) {
            Matcher orMatcher = OR_PATTERN.matcher(trimmed);
            if (orMatcher.matches() == false) {
                throw new IllegalArgumentException("@OR found with invalid format: " + line);
            }
            OrSqlFragment orFragment = new OrSqlFragment(orMatcher.group(1),
                    StringUtils.strip(orMatcher.group(2), " ="));
            parseContainerSection(orFragment, lineIterator, line.indent());
            if (orFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@OR found with no subsequent indented lines: " + line);
            }
            container.addFragment(orFragment);

        } else if (trimmed.startsWith("@IF")) {
            Matcher ifMatcher = IF_PATTERN.matcher(trimmed);
            if (ifMatcher.matches() == false) {
                throw new IllegalArgumentException("@IF found with invalid format: " + line);
            }
            IfSqlFragment ifFragment = new IfSqlFragment(ifMatcher.group(1),
                    StringUtils.strip(ifMatcher.group(2), " ="));
            parseContainerSection(ifFragment, lineIterator, line.indent());
            if (ifFragment.getFragments().size() == 0) {
                throw new IllegalArgumentException("@IF found with no subsequent indented lines: " + line);
            }
            container.addFragment(ifFragment);

        } else {
            parseLine(container, line);
        }
    }
}

From source file:marytts.unitselection.analysis.ProsodyAnalyzer.java

/**
 * For debugging, generate Praat PitchTier, which can be used for PSOLA-based manipulation in Praat.
 * //from ww w. j av a 2 s  .co  m
 * @param fileName
 *            of the PitchTier to be generated
 * @throws IOException
 */
public void writePraatPitchTier(String fileName) throws IOException {

    // initialize times and values:
    ArrayList<Double> times = new ArrayList<Double>();
    ArrayList<Double> values = new ArrayList<Double>();

    // cumulative time pointer:
    double time = 0;

    // iterate over phones, skipping the initial silence:
    ListIterator<Phone> phoneIterator = phones.listIterator(1);
    while (phoneIterator.hasNext()) {
        Phone phone = phoneIterator.next();
        double[] frameTimes = phone.getRealizedFrameDurations();
        double[] frameF0s = phone.getUnitFrameF0s();
        for (int f = 0; f < frameF0s.length; f++) {
            time += frameTimes[f];
            times.add(time);
            values.add(frameF0s[f]);
        }
    }

    // open file for writing:
    File durationTierFile = new File(fileName);
    PrintWriter out = new PrintWriter(durationTierFile);

    // print header:
    out.println("\"ooTextFile\"");
    out.println("\"PitchTier\"");
    out.println(String.format("0 %f %d", time, times.size()));

    // print points (times and values):
    for (int i = 0; i < times.size(); i++) {
        out.println(String.format("%.16f %f", times.get(i), values.get(i)));
    }

    // flush and close:
    out.close();
}

From source file:vteaexploration.plotgatetools.gates.PolygonGate.java

@Override
public Path2D createPath2DInChartSpace() {

    Point2D p;// ww  w .  j  av  a2s . co m
    Path2D.Double polygon = new Path2D.Double();

    ListIterator<Point2D.Double> itr = verticesInChartSpace.listIterator();

    p = (Point2D) verticesInChartSpace.get(0);
    //System.out.println(verticesInChartSpace.size() + " Gate points");
    //System.out.println("First Point: " + p);
    polygon.moveTo(p.getX(), p.getY());
    while (itr.hasNext()) {
        p = (Point2D) itr.next();
        //System.out.println("Next Point: " + p);
        polygon.lineTo(p.getX(), p.getY());
    }
    polygon.closePath();
    return polygon;

}

From source file:org.apache.solr.handler.component.HttpShardHandler.java

/**
 * A distributed request is made via {@link LBHttpSolrClient} to the first live server in the URL list.
 * This means it is just as likely to choose current host as any of the other hosts.
 * This function makes sure that the cores of current host are always put first in the URL list.
 * If all nodes prefer local-cores then a bad/heavily-loaded node will receive less requests from healthy nodes.
 * This will help prevent a distributed deadlock or timeouts in all the healthy nodes due to one bad node.
 *///from   w ww.j a va  2s . c  o m
private void preferCurrentHostForDistributedReq(final String currentHostAddress, final List<String> urls) {
    if (log.isDebugEnabled())
        log.debug("Trying to prefer local shard on {} among the urls: {}", currentHostAddress,
                Arrays.toString(urls.toArray()));

    ListIterator<String> itr = urls.listIterator();
    while (itr.hasNext()) {
        String url = itr.next();
        if (url.startsWith(currentHostAddress)) {
            // move current URL to the fore-front
            itr.remove();
            urls.add(0, url);

            if (log.isDebugEnabled())
                log.debug("Applied local shard preference for urls: {}", Arrays.toString(urls.toArray()));

            break;
        }
    }
}

From source file:com.caricah.iotracah.datastore.ignitecache.internal.impl.SubscriptionFilterHandler.java

public Observable<IotSubscriptionFilter> getTopicFilterTree(String partition,
        List<String> topicFilterTreeRoute) {

    return Observable.create(observer -> {

        List<Long> collectingParentIdList = new ArrayList<>();

        collectingParentIdList.add(0l);/*from  w ww.  ja  v  a 2s .  c om*/

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

        ListIterator<String> pathIterator = topicFilterTreeRoute.listIterator();

        try {

            while (pathIterator.hasNext()) {

                String topicPart = pathIterator.next();

                log.debug(" getTopicFilterTree : current path in tree is : {}", topicPart);

                growingTitles.add(topicPart);

                List<Long> parentIdList = new ArrayList<>(collectingParentIdList);
                collectingParentIdList.clear();

                for (Long parentId : parentIdList) {

                    log.debug(" getTopicFilterTree : Dealing with parent id : {} and titles is {}", parentId,
                            growingTitles);

                    if (Constant.MULTI_LEVEL_WILDCARD.equals(topicPart)) {

                        getMultiLevelWildCard(observer, partition, parentId);
                    } else if (Constant.SINGLE_LEVEL_WILDCARD.equals(topicPart)) {

                        String query = "partitionId = ? AND parentId = ? ";
                        Object[] params = { partition, parentId };

                        getByQuery(IotSubscriptionFilter.class, query, params).toBlocking()
                                .forEach(subscriptionFilter -> {

                                    log.debug(" getTopicFilterTree : Found matching single level filter : {}",
                                            subscriptionFilter);

                                    if (pathIterator.hasNext()) {
                                        collectingParentIdList.add(subscriptionFilter.getId());

                                    } else {
                                        observer.onNext(subscriptionFilter);
                                    }

                                });

                    } else {

                        String query = "partitionId = ? AND parentId = ? AND name = ? ";

                        String joinedTopicName = String.join(Constant.PATH_SEPARATOR, growingTitles);

                        Object[] params = new Object[] { partition, parentId, joinedTopicName };

                        getByQuery(IotSubscriptionFilter.class, query, params).toBlocking()
                                .forEach(subscriptionFilter -> {

                                    log.debug(" getTopicFilterTree : Found matching point filter : {}",
                                            subscriptionFilter);

                                    if (pathIterator.hasNext()) {
                                        collectingParentIdList.add(subscriptionFilter.getId());
                                    } else {
                                        observer.onNext(subscriptionFilter);
                                    }

                                });

                    }
                }

            }

            observer.onCompleted();

        } catch (Exception e) {
            observer.onError(e);
        }

    });

}