Example usage for java.util ListIterator nextIndex

List of usage examples for java.util ListIterator nextIndex

Introduction

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

Prototype

int nextIndex();

Source Link

Document

Returns the index of the element that would be returned by a subsequent call to #next .

Usage

From source file:org.graylog.plugins.collector.configurations.CollectorConfigurationService.java

public CollectorConfiguration updateSnippetFromRequest(String id, String snippetId,
        CollectorConfigurationSnippet request) {
    CollectorConfiguration collectorConfiguration = dbCollection.findOne(DBQuery.is("_id", id));

    ListIterator<CollectorConfigurationSnippet> snippetIterator = collectorConfiguration.snippets()
            .listIterator();//from  w  w  w.ja  va  2 s  .  c  om
    while (snippetIterator.hasNext()) {
        int i = snippetIterator.nextIndex();
        CollectorConfigurationSnippet snippet = snippetIterator.next();
        if (snippet.snippetId().equals(snippetId)) {
            collectorConfiguration.snippets().set(i, request);
        }
    }
    return collectorConfiguration;
}

From source file:com.hyperaware.conference.android.fragment.SessionFeedbackFragment.java

private void updateSessionFeedback() {
    final LayoutInflater inflater = getActivity().getLayoutInflater();
    tvTopic.setText(agendaItem.getTopic());

    final Map<String, SpeakerItem> speakersItems = speakers.getItems();
    vgSpeakers.removeAllViews();/*w w w.j av a2 s  .  c om*/
    for (final String id : agendaItem.getSpeakerIds()) {
        final SpeakerItem item = speakersItems.get(id);
        if (item != null) {
            TextView tv_speaker = (TextView) inflater.inflate(R.layout.inc_feedback_speaker, vgSpeakers, false);
            tv_speaker.setText(item.getName());
            vgSpeakers.addView(tv_speaker);
        }
    }

    vgQuestions.removeAllViews();
    final ListIterator<FeedbackQuestion> it = questions.listIterator();
    while (it.hasNext()) {
        int i = it.nextIndex();
        final FeedbackQuestion question = it.next();

        Object prior = null;
        if (priorAnswers.size() > i) {
            prior = priorAnswers.get(i);
        }

        final FeedbackCardView card;
        switch (question.getType()) {
        case Rate5:
            card = (FeedbackCardView) inflater.inflate(R.layout.card_feedback_question_rate, vgQuestions,
                    false);
            if (prior instanceof Number) {
                final RatingFeedbackCardView ratingcv = (RatingFeedbackCardView) card;
                ratingcv.setRating(((Number) prior).floatValue());
            }
            break;
        case YN:
            card = (FeedbackCardView) inflater.inflate(R.layout.card_feedback_question_yn, vgQuestions, false);
            if (prior instanceof Boolean) {
                final YesNoFeedbackCardView yncv = (YesNoFeedbackCardView) card;
                yncv.setChoice((Boolean) prior);
            }
            break;
        case Text:
        default:
            card = (FeedbackCardView) inflater.inflate(R.layout.card_feedback_question_text, vgQuestions,
                    false);
            if (prior instanceof String) {
                final TextFeedbackCardView tcv = (TextFeedbackCardView) card;
                tcv.setText((String) prior);
            }
            break;
        }
        card.setQuestionText(question.getText());
        allCards.add(card);
        vgQuestions.addView(card);
    }
}

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 .jav a2  s . c o m*/
 * @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:com.google.gwt.emultest.java.util.ListTestBase.java

public void testListIteratorHasNextHasPreviousAndIndexes() {
    List l = makeEmptyList();//from  ww  w.  j  a v a2 s  .c  o m
    ListIterator i = l.listIterator();
    assertFalse(i.hasNext());
    assertFalse(i.hasPrevious());
    i.add(new Integer(1));
    assertEquals(1, i.nextIndex());
    assertEquals(0, i.previousIndex());
    i = l.listIterator();
    assertEquals(0, i.nextIndex());
    assertEquals(-1, i.previousIndex());
    assertTrue(i.hasNext());
    assertFalse(i.hasPrevious());
    i.next();
    assertEquals(1, i.nextIndex());
    assertEquals(0, i.previousIndex());
    assertFalse(i.hasNext());
    assertTrue(i.hasPrevious());
}

From source file:io.bibleget.BibleGetFrame.java

/**
 *
 * @throws ClassNotFoundException/*w w w  . j ava2s. c  o m*/
 */
private void prepareDynamicInformation() throws ClassNotFoundException {
    biblegetDB = BibleGetDB.getInstance();
    String bibleVersionsStr = biblegetDB.getMetaData("VERSIONS");
    JsonReader jsonReader = Json.createReader(new StringReader(bibleVersionsStr));
    JsonObject bibleVersionsObj = jsonReader.readObject();
    Set<String> versionsabbrev = bibleVersionsObj.keySet();
    bibleVersions = new BasicEventList<>();
    if (!versionsabbrev.isEmpty()) {
        for (String s : versionsabbrev) {
            String versionStr = bibleVersionsObj.getString(s); //store these in an array
            String[] array;
            array = versionStr.split("\\|");
            bibleVersions.add(new BibleVersion(s, array[0], array[1],
                    StringUtils.capitalize(new Locale(array[2]).getDisplayLanguage())));
        }
    }

    List<String> preferredVersions = new ArrayList<>();
    String retVal = (String) biblegetDB.getOption("PREFERREDVERSIONS");
    if (null == retVal) {
        //System.out.println("Attempt to retrieve PREFERREDVERSIONS from the Database resulted in null value");
    } else {
        //System.out.println("Retrieved PREFERREDVERSIONS from the Database. Value is:"+retVal);
        String[] favoriteVersions = StringUtils.split(retVal, ',');
        preferredVersions = Arrays.asList(favoriteVersions);
    }
    if (preferredVersions.isEmpty()) {
        preferredVersions.add("NVBSE");
    }
    List<Integer> preferredVersionsIndices = new ArrayList<>();

    versionsByLang = new SeparatorList<>(bibleVersions, new VersionComparator(), 1, 1000);
    int listLength = versionsByLang.size();
    enabledFlags = new boolean[listLength];
    ListIterator itr = versionsByLang.listIterator();
    while (itr.hasNext()) {
        int idx = itr.nextIndex();
        Object next = itr.next();
        enabledFlags[idx] = !(next.getClass().getSimpleName().equals("GroupSeparator"));
        if (next.getClass().getSimpleName().equals("BibleVersion")) {
            BibleVersion thisBibleVersion = (BibleVersion) next;
            if (preferredVersions.contains(thisBibleVersion.getAbbrev())) {
                preferredVersionsIndices.add(idx);
            }
        }
    }
    indices = ArrayUtils
            .toPrimitive(preferredVersionsIndices.toArray(new Integer[preferredVersionsIndices.size()]));
    //System.out.println("value of indices array: "+Arrays.toString(indices));

}

From source file:org.cloudata.core.common.conf.CloudataConf.java

private void toString(ArrayList resources, StringBuffer sb) {
    ListIterator i = resources.listIterator();
    while (i.hasNext()) {
        if (i.nextIndex() != 0) {
            sb.append(" , ");
        }//from   www . ja va2 s .c o m
        sb.append(i.next());
    }
}

From source file:org.orekit.files.ccsds.OEMFile.java

/** {@inheritDoc} */
@Override/*from   w  w  w .j a va2  s.com*/
public List<SatelliteTimeCoordinate> getSatelliteCoordinates(final String satId) {
    // first we collect all available EphemeridesBlocks for this satellite
    // and return a list view of the actual EphemeridesBlocks transforming the
    // EphemeridesDataLines into SatelliteTimeCoordinates in a lazy manner.
    final List<Pair<Integer, Integer>> ephemeridesBlockMapping = new ArrayList<Pair<Integer, Integer>>();
    final ListIterator<EphemeridesBlock> it = ephemeridesBlocks.listIterator();
    int totalDataLines = 0;
    while (it.hasNext()) {
        final int index = it.nextIndex();
        final EphemeridesBlock block = it.next();

        if (block.getMetaData().getObjectID().equals(satId)) {
            final int dataLines = block.getEphemeridesDataLines().size();
            totalDataLines += dataLines;
            ephemeridesBlockMapping.add(new Pair<Integer, Integer>(index, dataLines));
        }
    }

    // the total number of coordinates for this satellite
    final int totalNumberOfCoordinates = totalDataLines;

    return new AbstractList<SatelliteTimeCoordinate>() {

        @Override
        public SatelliteTimeCoordinate get(final int index) {
            if (index < 0 || index >= size()) {
                throw new IndexOutOfBoundsException();
            }

            // find the corresponding ephemerides block and data line
            int ephemeridesBlockIndex = -1;
            int dataLineIndex = index;
            for (Pair<Integer, Integer> pair : ephemeridesBlockMapping) {
                if (dataLineIndex < pair.getValue()) {
                    ephemeridesBlockIndex = pair.getKey();
                    break;
                } else {
                    dataLineIndex -= pair.getValue();
                }
            }

            if (ephemeridesBlockIndex == -1 || dataLineIndex == -1) {
                throw new IndexOutOfBoundsException();
            }

            final EphemeridesDataLine dataLine = ephemeridesBlocks.get(ephemeridesBlockIndex)
                    .getEphemeridesDataLines().get(dataLineIndex);
            final CartesianOrbit orbit = dataLine.getOrbit();
            return new SatelliteTimeCoordinate(orbit.getDate(), orbit.getPVCoordinates());
        }

        @Override
        public int size() {
            return totalNumberOfCoordinates;
        }

    };
}

From source file:lcn.module.batch.web.guide.support.StagingItemWriter.java

/**
 * BATCH_STAGING? write/*w w  w.j  ava 2 s  . c  o m*/
 */
public void write(final List<? extends T> items) {

    final ListIterator<? extends T> itemIterator = items.listIterator();
    getJdbcTemplate().batchUpdate("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
            new BatchPreparedStatementSetter() {

                public int getBatchSize() {
                    return items.size();
                }

                public void setValues(PreparedStatement ps, int i) throws SQLException {

                    long id = incrementer.nextLongValue();
                    long jobId = stepExecution.getJobExecution().getJobId();

                    Assert.state(itemIterator.nextIndex() == i,
                            "Item ordering must be preserved in batch sql update");

                    byte[] blob = SerializationUtils.serialize((Serializable) itemIterator.next());

                    ps.setLong(1, id);
                    ps.setLong(2, jobId);
                    ps.setBytes(3, blob);
                    ps.setString(4, NEW);
                }
            });

}

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

private int computeContentLength(PrimaryGridUnit pgu, int startIndex, int endIndex) {
    if (startIndex > endIndex) {
        // May happen if the cell contributes no content on the current page (empty
        // cell, in most cases)
        return 0;
    } else {//w  w w  .  j av a 2s. com
        ListIterator iter = pgu.getElements().listIterator(startIndex);
        // Skip from the content length calculation glues and penalties occurring at the
        // beginning of the page
        boolean nextIsBox = false;
        while (iter.nextIndex() <= endIndex && !nextIsBox) {
            nextIsBox = ((KnuthElement) iter.next()).isBox();
        }
        int len = 0;
        if (((KnuthElement) iter.previous()).isBox()) {
            while (iter.nextIndex() < endIndex) {
                KnuthElement el = (KnuthElement) iter.next();
                if (el.isBox() || el.isGlue()) {
                    len += el.getWidth();
                }
            }
            len += ActiveCell.getElementContentLength((KnuthElement) iter.next());
        }
        return len;
    }
}

From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java

private void handleGroup(List destList, ListIterator groupIterator, Node parentGroup, NodeGroup group,
        GraphicNode last, List nodes, NodeTransformer composition, boolean preserveHierarchy) {
    GraphicNode groupNode = createGroup(groupIterator.nextIndex(), group, group.getSorter(), last.getNode());
    destList.add(groupNode);/*  w ww  .ja v a  2 s .  c  o  m*/
    model.addRelationship(parentGroup, groupNode.getNode());
    if (groupIterator.hasNext()) {
        groupList(nodes, destList, groupIterator, groupNode.getNode(), composition, preserveHierarchy);
    } else {
        for (Iterator j = nodes.iterator(); j.hasNext();)
            model.addRelationship(groupNode.getNode(), ((GraphicNode) j.next()).getNode());
        destList.addAll(nodes);
    }
}