Example usage for java.util List remove

List of usage examples for java.util List remove

Introduction

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

Prototype

E remove(int index);

Source Link

Document

Removes the element at the specified position in this list (optional operation).

Usage

From source file:com.yunmel.syncretic.utils.commons.CollectionsUtils.java

/**
 * a-bList.//w w  w .j  av  a  2 s .c  o  m
 */
public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) {
    List<T> list = Lists.newArrayList(a);
    for (T element : b) {
        list.remove(element);
    }

    return list;
}

From source file:Main.java

/**
 * Samples without replacement from a collection, using your own
 * {@link Random} number generator.//w w  w.j a  va 2  s  .  co  m
 *
 * @param c
 *          The collection to be sampled from
 * @param n
 *          The number of samples to take
 * @param r
 *          the random number generator
 * @return a new collection with the sample
 */
public static <E> Collection<E> sampleWithoutReplacement(Collection<E> c, int n, Random r) {
    if (n < 0)
        throw new IllegalArgumentException("n < 0: " + n);
    if (n > c.size())
        throw new IllegalArgumentException("n > size of collection: " + n + ", " + c.size());
    List<E> copy = new ArrayList<E>(c.size());
    copy.addAll(c);
    Collection<E> result = new ArrayList<E>(n);
    for (int k = 0; k < n; k++) {
        double d = r.nextDouble();
        int x = (int) (d * copy.size());
        result.add(copy.remove(x));
    }
    return result;
}

From source file:it.geosolutions.geobatch.destination.vulnerability.TargetPropertiesLoader.java

public static List<Double> loadDistances(DataStore dataStore, String featureTypeName) {
    List<Double> list = FeatureLoaderUtils.loadFeatureAttributesInt(dataStore, featureTypeName,
            DISTANZA_ATTRIBUTE_NAME, true);
    list.remove(new Double(0.0d));
    return list;/*  ww w  .j a  v a2 s.  co m*/
}

From source file:Main.java

@Deprecated
public static void filterList(List<Map<String, Object>> list, String key) {

    List<Object> keys = new ArrayList<>();
    for (Map<String, Object> map : list) {

        Object object = map.get(key);

        if (!keys.contains(object)) {

            keys.add(object);//from   w w  w  .j  av a  2  s. c  o m
        } else {

            list.remove(map);
        }
    }
}

From source file:Main.java

public static <T> void exchange(List<T> list, int indexA, int indexB) {
    indexA -= 1;//from  w w w  . j av  a  2 s.c o  m
    indexB -= 1;

    if (indexA >= list.size() || indexB >= list.size() || indexA < 0 || indexB < 0 || indexA == indexB) {
        return;
    } else {
        T _a = list.get(indexA);
        T _b = list.get(indexB);
        list.remove(indexA);
        list.add(indexA, _b);
        list.remove(indexB);
        list.add(indexB, _a);
        return;
    }
}

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

/**
 * Deletes the element at the specified index from the list.
 *
 * @param lst the list.// w  w  w.ja v a  2 s  .c om
 * @param index the index of the object to be deleted.
 */
private static void deleteElementFromList(List<InputOutputObject> lst, Long deleteIndex) {
    if ((lst != null) && (deleteIndex.intValue() >= 0) && (lst.size() > 0)) {
        lst.remove(deleteIndex.intValue());
    }
}

From source file:hydrograph.server.execution.tracking.client.main.HydrographMain.java

private static List<String> removeItemFromIndex(int index, List<String> argList) {

    argList.remove(index); /* removing parameter name */
    argList.remove(index); /* removing parameter value */

    return argList;

}

From source file:au.com.gworks.gwt.petstore.server.ShoppingRpcControllerImpl.java

static private void moveFavouriteToFront(List/*<AisleInfo>*/ list, String fav) {
    for (int i = 0; i < list.size(); i++) {
        if (fav.equals(((AisleInfo) list.get(i)).id)) {
            AisleInfo favAisle = (AisleInfo) list.remove(i);
            list.add(0, favAisle);//from   ww  w .j  a v  a2s  . c  om
            return;
        }
    }
}

From source file:edu.wpi.checksims.util.PairGenerator.java

/**
 * Generate all possible unique, unordered pairs of submissions.
 *
 * @param submissions Submissions to generate pairs from
 * @return Set of all unique, unordered pairs of submissions
 */// w ww . j  av a 2  s .com
public static Set<Pair<Submission, Submission>> generatePairs(Set<Submission> submissions) {
    checkNotNull(submissions);
    checkArgument(submissions.size() >= 2, "Cannot generate pairs with less than 2 submissions!");

    Set<Pair<Submission, Submission>> pairs = new HashSet<>();

    List<Submission> remaining = new ArrayList<>();
    remaining.addAll(submissions);

    while (remaining.size() >= 2) {
        // Get the first submission in the list and remove it
        Submission first = remaining.get(0);
        remaining.remove(0);

        // Form a pair for every remaining submission by pairing with the first, removed submission
        for (Submission submission : remaining) {
            Pair<Submission, Submission> pair = Pair.of(first, submission);
            Pair<Submission, Submission> reversed = Pair.of(submission, first);

            // Something's wrong, we've made a duplicate pair (but reversed)
            // Should never happen
            if (pairs.contains(reversed)) {
                throw new RuntimeException("Internal error in pair generation: duplicate pair produced!");
            }

            // Add the newly-generated pair to our return
            pairs.add(pair);
        }
    }

    return pairs;
}

From source file:org.vaadin.peholmst.samples.dddwebinar.TestDataGenerator.java

private static <T> Set<T> pickRandom(Set<T> source, int count) {
    List<T> src = new ArrayList<>(source);
    Set<T> dest = new HashSet<>();
    for (int i = 0; i < count; ++i) {
        dest.add(src.remove(RND.nextInt(src.size())));
    }//from   www  . ja v  a  2  s.c o m
    return dest;
}