Java ListIterator Usage getAll_SequentialAccess( List idxs, List values)

Here you can find the source of getAll_SequentialAccess( List idxs, List values)

Description

Takes all values specified by the given idxs (which must be in ascending order) from values through the use of a ListIterator.

License

LGPL

Declaration

public static <V> LinkedList<V> getAll_SequentialAccess(
        List<Integer> idxs, List<V> values) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Main {
    /**// www  .  ja va 2s .  c  o m
     * Takes all values specified by the given <tt>idxs</tt> (which must be in ascending order) 
     * from <tt>values</tt> through the use of a ListIterator.
     */
    public static <V> LinkedList<V> getAll_SequentialAccess(
            List<Integer> idxs, List<V> values) {
        LinkedList<V> taken = new LinkedList<V>();

        ListIterator<V> valueIter = values.listIterator();
        int valuesIdx = -1;
        V value = null;

        int lastIdx = -1;
        for (int idx : idxs) {
            assert idx >= lastIdx;
            lastIdx = idx; // ensure that the index list is sorted
            while (valuesIdx < idx) {
                value = valueIter.next();
                valuesIdx++;
            }
            taken.add(value);
        }
        return taken;
    }
}

Related

  1. emptyIterator()
  2. filterStringList(final String prefix, final String infix, final String suffix, final List list)
  3. findFirstIterator(List list, int fromIndex, int toIndex, T value, Comparator comparator)
  4. findObject(Object item, ListIterator iter)
  5. findPrevious(ListIterator iter)
  6. getCamelNameSegments(String camelName)
  7. getCurrentElement(ListIterator listIterator)
  8. getLastNonNull(List l)
  9. goToFirst(ListIterator iterator)