Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:Main.java

/**
 * combines all the lists in a collection to a single list
 *//*from  w  w  w . j  a v a  2 s  . c  o m*/
public static <T> List<T> flatten(Collection<List<T>> nestedList) {
    List<T> result = new ArrayList<T>();
    for (List<T> list : nestedList) {
        result.addAll(list);
    }
    return result;
}

From source file:Main.java

/**
 * Samples without replacement from a collection, using your own
 * {@link Random} number generator.//w  ww .j  av a 2s. c  om
 *
 * @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:fi.hsl.parkandride.core.domain.PredictionResult.java

public static List<PredictionResult> from(Optional<PredictionBatch> batch) {
    List<PredictionResult> results = new ArrayList<>();
    batch.ifPresent(pb -> results.addAll(from(pb)));
    return results;
}

From source file:Main.java

private static List<String> filterParamNames(Map<String, Object> paramValueMap,
        List<String> ignoreParamNameList) {
    List<String> filteredParamNames = new ArrayList<>(paramValueMap.size());
    filteredParamNames.addAll(paramValueMap.keySet());
    if (ignoreParamNameList != null && ignoreParamNameList.size() > 0) {
        for (String ignoreParamName : ignoreParamNameList) {
            filteredParamNames.remove(ignoreParamName);
        }/*from   ww w.  j  a  v a 2 s.  c o  m*/
    }
    return filteredParamNames;
}

From source file:Main.java

public static <T> List<T> union(List<T> list1, List<T> list2, boolean duplicate) {
    if (list1 == null || list2 == null) {
        return (list1 == null) ? new ArrayList<T>(list2) : new ArrayList<T>(list1);
    }/*  w  w w  .ja  v  a2 s  . c  o m*/
    List<T> ret;
    if (duplicate) {
        ret = new ArrayList<T>(list1);
        ret.addAll(list2);
    } else {
        Set<T> set = union(new HashSet<T>(list1), new HashSet<T>(list2));
        ret = new ArrayList<T>(set);
    }
    return ret;
}

From source file:Main.java

public static <ELEMENT extends Object> List<List<ELEMENT>> splitByLimit(List<ELEMENT> elementList, int limit) {
    final List<List<ELEMENT>> valueList = newArrayList();
    final int valueSize = elementList.size();
    int index = 0;
    int remainderSize = valueSize;
    do {/*from  w w  w .ja  va2  s  .  c om*/
        final int beginIndex = limit * index;
        final int endPoint = beginIndex + limit;
        final int endIndex = limit <= remainderSize ? endPoint : valueSize;
        final List<ELEMENT> splitList = newArrayList();
        splitList.addAll(elementList.subList(beginIndex, endIndex));
        valueList.add(splitList);
        remainderSize = valueSize - endIndex;
        ++index;
    } while (remainderSize > 0);
    return valueList;
}

From source file:Main.java

public static final <E> List<E> flatten(Collection<?>... collections) {
    List<E> resultList = new ArrayList<>();

    for (Collection<?> collection : collections) {
        resultList.addAll((Collection<? extends E>) collection);
    }/*  ww  w .  j av  a2 s . c  om*/

    return new ArrayList<>(new LinkedHashSet<>(resultList));
}

From source file:Main.java

public static List union(List srcList, List destList) {
    List list = new ArrayList<>(Arrays.asList(new Object[srcList.size()]));
    Collections.copy(list, srcList);
    list.addAll(destList);
    return list;//from   w w  w . j a  v  a 2s.c om
}

From source file:org.xmatthew.spy2servers.core.context.ComponentContextUtils.java

@SuppressWarnings("unchecked")
public static ComponentContext getComponentContext(ApplicationContext context) {
    Map beansMap = context.getBeansOfType(Component.class);
    if (beansMap != null) {

        List<Component> components = new ArrayList<Component>(beansMap.size());
        components.addAll(beansMap.values());
        ComponentContext componentContext = new ComponentContext();
        componentContext.setComponents(components);
        return componentContext;
    }/* www . j  a va2 s .co m*/
    return null;
}

From source file:Main.java

public static List<Object> merge(List<Object>... lists) {
    List<Object> ret = new ArrayList<Object>();
    for (List<Object> list : lists) {
        ret.addAll(list);
    }//ww w .ja  va 2 s . c  om
    return ret;
}