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:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java

/**
 * Removes the invalid items (inputs/outputs with blank name, filename and notes) from the list.
 *
 * @param lst the list of inputs/outputs.
 *///from   www  .ja  v a  2s .  c  om
public static void removeInvalidItems(List<InputOutputObject> lst) {
    ListIterator<InputOutputObject> listIter = lst.listIterator();
    while (listIter.hasNext()) {
        InputOutputObject ioObject = listIter.next();
        if (StringUtils.isBlank(ioObject.getName()) && StringUtils.isBlank(ioObject.getDataFileURL())
                && StringUtils.isBlank(ioObject.getNotes())) {
            listIter.remove();
        }
    }
}

From source file:Main.java

public static <E> boolean addToSortedList(List<E> list, E item, Comparator<? super E> comparator,
        BiPredicate<? super E, ? super E> distincter) {
    int addIndex = list.size();
    boolean foundAddIndex = false;
    ListIterator<E> iter = list.listIterator();
    while (iter.hasNext()) {
        int currIndex = iter.nextIndex();
        E currItem = iter.next();//from  ww  w.j  av a  2 s.  c  o  m
        if (distincter != null && distincter.test(currItem, item)) {
            return false;
        }
        if (!foundAddIndex) {
            int comparison = comparator.compare(currItem, item);
            if (comparison > 0) {
                addIndex = currIndex;
                // if we don't have to check the remaining items for distinct we can break the loop now
                if (distincter == null) {
                    break;
                }
                foundAddIndex = true;
            } else if (comparison == 0) {
                addIndex = currIndex + 1;
                // if we don't have to check the remaining items for distinct we can break the loop now
                if (distincter == null) {
                    break;
                }
                foundAddIndex = true;
            }
        }
    }
    list.add(addIndex, item);
    return true;
}

From source file:org.apache.cocoon.components.modules.input.JXPathHelper.java

public static Iterator getAttributeNames(JXPathHelperConfiguration setup, Object contextObj)
        throws ConfigurationException {

    if (contextObj == null) {
        return null;
    }/*from   w w w. j  av  a2 s.  c  o  m*/

    try {
        JXPathBeanInfo info = JXPathIntrospector.getBeanInfo(contextObj.getClass());
        java.beans.PropertyDescriptor[] properties = info.getPropertyDescriptors();

        List names = new LinkedList();
        for (int i = 0; i < properties.length; i++) {
            names.add(properties[i].getName());
        }

        return names.listIterator();
    } catch (Exception e) {
        throw new ConfigurationException("Error retrieving attribute names for class: " + contextObj.getClass(),
                e);
    }
}

From source file:mitm.common.util.StringReplaceUtils.java

/**
 * For each String in the list the non-XML characters are replaced. The returned list is the same instance as input
 * (it's an in place replacement)//from www. j  ava2  s.c  om
 */
public static List<String> replaceNonXML(List<String> input, String replaceWith) {
    Check.notNull(replaceWith, "replaceWith");

    if (input == null) {
        return null;
    }

    ListIterator<String> listIterator = input.listIterator();

    while (listIterator.hasNext()) {
        String line = listIterator.next();

        listIterator.set(StringReplaceUtils.replaceNonXML(line, "#"));
    }

    return input;
}

From source file:Main.java

/**
 * Finds the first index where the value is located or
 * the index where it could be inserted, similar to the regular
 * binarySearch() methods, but it works with duplicate elements.
 * @param <T> the element type//w  w w .  j  ava 2 s .  c o m
 * @param list the list to search
 * @param fromIndex the starting index, inclusive
 * @param toIndex the end index, exclusive
 * @param value the value to search
 * @param comparator the comparator
 * @return if positive, the exact index where the value is first
 * encountered, or -(insertion point - 1) if not in the array.
 */
public static <T> int findFirstIterator(List<? extends T> list, int fromIndex, int toIndex, T value,
        Comparator<? super T> comparator) {
    int a = fromIndex;
    int b = toIndex;
    ListIterator<? extends T> it = list.listIterator();
    while (a <= b) {
        int mid = a + (b - a) / 2;
        T midVal = get(it, mid);
        int c = comparator.compare(midVal, value);
        if (c < 0) {
            a = mid + 1;
        } else if (c > 0) {
            b = mid - 1;
        } else {
            if (mid > 0) {
                if (comparator.compare(get(it, mid - 1), value) != 0) {
                    return mid;
                } else {
                    b = mid - 1;
                }
            } else {
                return 0;
            }
        }
    }
    return -(a + 1);
}

From source file:Main.java

/**
 * Finds the last index where the value is located or
 * the index where it could be inserted, similar to the regular
 * binarySearch() methods, but it works with duplicate elements.
 * @param <T> the element type//from  w ww  .java  2s.com
 * @param list the list to search
 * @param fromIndex the starting index, inclusive
 * @param toIndex the end index, exclusive
 * @param value the value to search
 * @param comparator the comparator
 * @return if positive, the exact index where the value is first
 * encountered, or -(insertion point - 1) if not in the array.
 */
public static <T> int findLastIterator(List<? extends T> list, int fromIndex, int toIndex, T value,
        Comparator<? super T> comparator) {
    int a = fromIndex;
    int b = toIndex;
    ListIterator<? extends T> it = list.listIterator();
    while (a <= b) {
        int mid = a + (b - a) / 2;
        T midVal = get(it, mid);
        int c = comparator.compare(midVal, value);
        if (c < 0) {
            a = mid + 1;
        } else if (c > 0) {
            b = mid - 1;
        } else {
            if (mid < toIndex - 1) {
                if (comparator.compare(get(it, mid + 1), value) != 0) {
                    return mid;
                } else {
                    a = mid + 1;
                }
            } else {
                return 0;
            }
        }
    }
    return -(a + 1);
}

From source file:Main.java

public static <E> void swapAll(final List<E> list) {
    if (list instanceof RandomAccess) {
        for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
            list.set(i, list.set(j, list.get(i)));
        }/*ww  w  . j  a v  a  2  s.c o  m*/
    } else {
        final ListIterator<E> iteratorI = list.listIterator();
        final ListIterator<E> iteratorJ = list.listIterator(list.size());
        E tmp;

        while (iteratorI.nextIndex() < iteratorJ.nextIndex()) {
            tmp = iteratorI.next();
            iteratorI.set(iteratorJ.previous());
            iteratorJ.set(tmp);
        }
    }
}

From source file:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java

/**
 * Removes potential duplicate inputs from the list.
 *
 * @param lstInputs the protocol application inputs.
 * @param lstPotentialInputs the list of potential inputs.
 *//* w w  w .ja  v  a  2 s.co  m*/
private static void removeDuplicateInputs(List<InputOutputObject> lstInputs,
        List<InputOutputObject> lstPotentialInputs) {
    ListIterator<InputOutputObject> iterPAInputs = lstInputs.listIterator();
    while (iterPAInputs.hasNext()) {
        InputOutputObject currentInput = iterPAInputs.next();
        if ((currentInput.getId() != null) && !StringUtils.isBlank(currentInput.getId().toString())
                && lstPotentialInputs.contains(currentInput)) {
            lstPotentialInputs.remove(currentInput);
        }
    }
}

From source file:edu.kit.cockpit.valuationserver.pollgenerator.PollGenerator.java

/**
 * Extract service attributes from evaluation's SFM model resource
 * /* w  w w.  ja  v  a2 s .  c  o  m*/
 * @param eval
 * @return array of attribute names
 */
public static List<AttributeType> getComparableSFMAttributes(EvaluationE eval) {

    // Extract service object from associated SFM model
    Service service = null;
    try {
        SFMPersistency sfmpersistency = new SFMPersistency();
        Resource resource = sfmpersistency.loadSFMModelToResource(SFMPersistency.getModelId(eval.getId()));
        service = EMFUtil.getService(resource);
    } catch (IOException e1) {
        log.error(e1);
        return null;
    }

    // construct list of comparable service attribute types
    List<AttributeType> attributeList = service.getAttributeTypes().getAttributeTypes();
    List<AttributeType> compareList = new LinkedList<AttributeType>();
    for (Iterator<AttributeType> iter = attributeList.listIterator(); iter.hasNext();) {
        AttributeType tempAT = (AttributeType) iter.next();
        if (tempAT != null && tempAT.isToBeEvaluated() == true) {
            compareList.add(tempAT);
        }
    }
    return compareList;
}

From source file:exm.stc.ic.ICUtil.java

public static void removeDuplicates(List<Var> varList) {
    ListIterator<Var> it = varList.listIterator();
    HashSet<Var> alreadySeen = new HashSet<Var>();
    while (it.hasNext()) {
        Var v = it.next();//from  w w w.j  a va  2s .  c  o  m
        if (alreadySeen.contains(v)) {
            it.remove();
        } else {
            alreadySeen.add(v);
        }
    }
}