Example usage for java.util Iterator remove

List of usage examples for java.util Iterator remove

Introduction

In this page you can find the example usage for java.util Iterator remove.

Prototype

default void remove() 

Source Link

Document

Removes from the underlying collection the last element returned by this iterator (optional operation).

Usage

From source file:de.hbz.lobid.helper.CompareJsonMaps.java

private static void removeContext(Iterator<String> it) {
    while (it.hasNext()) {
        String se = it.next();/*from  w w w. j  a v a  2 s.  c om*/
        if (IGNORE_CONTEXT && se.startsWith(JSON_LD_CONTEXT))
            it.remove();
    }
}

From source file:fi.smaa.libror.MaximalVectorComputation.java

/**
 * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007.
 * /* w  w w.  j  av  a2s  .c  o  m*/
 * Returns indices of the rows from the original matrix.
 * 
 * @param mat The matrix of values (each row = 1 vector of input)
 * 
 * @return Matrix containing rows from the input s.t. none are dominated
 */
public static int[] computeBESTindices(RealMatrix mat) {
    LinkedList<Integer> list = matrixToListOfIndices(mat);
    LinkedList<Integer> results = new LinkedList<Integer>();

    while (list.size() > 0) {
        Iterator<Integer> iter = list.iterator();
        Integer b = iter.next(); // Get the first
        iter.remove();
        while (iter.hasNext()) { // Find a max
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            } else if (dominates(mat.getRowVector(t), mat.getRowVector(b))) {
                iter.remove();
                b = t;
            }
        }
        results.add(b);
        iter = list.iterator();
        while (iter.hasNext()) { // Clean up
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            }
        }
    }

    return listOfIntegersToIntArray(results);
}

From source file:Main.java

public static void removeListPrefItems(ListPreference listPref, String[] labels, String[] values,
        List<String> items) {

    List<String> labelsList = new ArrayList<String>(Arrays.asList(labels));
    List<String> valuesList = new ArrayList<String>(Arrays.asList(values));

    Iterator<String> it = valuesList.iterator();
    while (it.hasNext()) {
        String value = it.next();
        if (items.contains(value)) {
            labelsList.remove(valuesList.indexOf(value));
            it.remove();
        }/*from  ww w.j  av a  2 s  . c o m*/
    }

    listPref.setEntries(labelsList.toArray(new String[1]));
    listPref.setEntryValues(valuesList.toArray(new String[1]));

}

From source file:fi.smaa.libror.MaximalVectorComputation.java

/**
 * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007.
 * /*w ww .  j  a  va2 s . c om*/
 * @param mat The matrix of values (each row = 1 vector of input)
 * 
 * @return Matrix containing rows from the input s.t. none are dominated
 */
public static RealMatrix computeBEST(RealMatrix mat) {
    LinkedList<RealVector> list = matrixToListOfRows(mat);
    LinkedList<RealVector> results = new LinkedList<RealVector>();

    while (list.size() > 0) {
        Iterator<RealVector> iter = list.iterator();
        RealVector b = iter.next(); // Get the first
        iter.remove();
        while (iter.hasNext()) { // Find a max
            RealVector t = iter.next();
            if (dominates(b, t)) {
                iter.remove();
            } else if (dominates(t, b)) {
                iter.remove();
                b = t;
            }
        }
        results.add(b);
        iter = list.iterator();
        while (iter.hasNext()) { // Clean up
            RealVector t = iter.next();
            if (dominates(b, t)) {
                iter.remove();
            }
        }
    }

    return listOfRowsToMatrix(results);
}

From source file:Main.java

/**
 * Filters all objects in the list against a specified collection. Either removes all items that
 * are found in specified collection or removes all items that are not found in the collection.
 * Uses {@link Iterator#remove()} to remove items from the target list.
 * /*  ww  w.j a  v a2s .c  o m*/
 * @param items collection of items acting as a filter
 * @param iter iterator over the target collection, from which items will be removed
 * @param remove true if <em>removing</em> all items found in the collection or false if
 *           <em>retaining</em> them
 * @return true if the list was modified and something was removed
 */
// TODO: add javadoc about using this to implement Collection.removeAll/retainAll
public static boolean filter(Collection<?> items, Iterator<?> iter, boolean remove) {
    boolean modified = false;
    while (iter.hasNext()) {
        if (items.contains(iter.next()) == remove) {
            iter.remove();
            modified = true;
        }
    }
    return modified;
}

From source file:com.fengduo.bee.commons.core.lang.ArrayUtils.java

public static String[] removeBlankElement(String[] array) {
    if (Argument.isEmptyArray(array)) {
        logger.debug("ArrayUtils.removeBlankElement array is null!");
        return null;
    }/* w w w .j  av  a2s  . c  o  m*/
    List<String> list = new ArrayList<String>(Arrays.asList(array));
    Iterator<String> iterator = list.iterator();
    while (iterator.hasNext()) {
        if (Argument.isBlank(iterator.next())) {
            iterator.remove();
        }
    }
    if (list.isEmpty()) {
        return null;
    } else {
        return list.toArray(new String[0]);
    }
}

From source file:java2typescript.jaxrs.model.RestService.java

/** Re,ove @Context parameters from JSON definition before rendering */
static private RestService copyWithoutContextParams(RestService restService) {
    Kryo kryo = new Kryo();
    RestService res = kryo.copy(restService);
    for (RestMethod method : res.getMethods().values()) {
        Iterator<Param> paramsIt = method.getParams().iterator();
        while (paramsIt.hasNext()) {
            Param param = paramsIt.next();
            if (param.isContext()) {
                paramsIt.remove();
            }/*from   ww  w . j  av a  2s  .c  o  m*/
        }
    }
    return res;
}

From source file:Main.java

/**
 * //  ww w .  java  2  s.c  o m
 * 
 */
public static <T> boolean equalsAsSet(Collection<T> value1, Collection<T> value2, Method equalsMethod)
        throws IllegalAccessException, InvocationTargetException {
    if (!equalsMethod.getReturnType().equals(boolean.class)) {
        return false;
    }
    List<T> s1 = new LinkedList<T>();
    for (T v : value1) {
        s1.add(v);
    }
    for (T v : value2) {
        Iterator<T> i2 = s1.iterator();
        boolean found = false;
        while (i2.hasNext()) {
            if (((Boolean) equalsMethod.invoke(v, i2.next())).booleanValue()) {
                i2.remove();
                found = true;
                break;
            }
        }
        if (!found)
            return false;
    }
    return s1.size() == 0;
}

From source file:com.jfinal.ext.plugin.sqlinxml.SqlKit.java

public static void removeSqlWithPrefix(File xmlFile) {
    String name = xmlFile.getName();
    int start = name.indexOf("-");
    String prefix = null;/*from w  ww . ja v  a  2s.c om*/
    if (start > -1) {
        prefix = name.substring(0, start);
    }

    if (prefix == null) {
        LOG.info("sql file " + xmlFile + " name is invalidate.");
        return;
    }

    Iterator<String> it = sqlMap.keySet().iterator();
    while (it.hasNext()) {
        if (it.next().startsWith(prefix)) {
            it.remove();
        }
    }
}

From source file:Main.java

/**
 * Returns itrator and filters for lower case.
 * /*from   w w  w. j a v  a 2s.c om*/
 * @param <T>
 *            Class for list where you get random item.
 * @param list
 *            Returns and itrator over the elements of T.
 * @param filter
 *            Filters for lower case.
 */
public static <T extends Iterable<String>> void filter(T list, String filter) {
    Iterator<? extends String> strI = list.iterator();
    while (strI.hasNext()) {
        String str = strI.next();
        if (!str.toLowerCase().contains(filter.toLowerCase())) {
            strI.remove();
        }
    }
}