Example usage for java.util Collections addAll

List of usage examples for java.util Collections addAll

Introduction

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

Prototype

@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

Source Link

Document

Adds all of the specified elements to the specified collection.

Usage

From source file:Main.java

/**
 * Extract all the fields of an object and its parent classes' fields iterative.
 * @param fields that belong to the class declaration.
 * @param type of the class from where extract the fields.
 * @return list of the fields fo the type class.
 *///from w  ww .ja  v a 2  s .c  o  m
private static List<Field> getAllFields(List<Field> fields, Class<?> type) {
    Collections.addAll(fields, type.getDeclaredFields());

    if (type.getSuperclass() != null) {
        fields = getAllFields(fields, type.getSuperclass());
    }

    return fields;
}

From source file:Main.java

/**
 * /*from   w  w w  .  j a  v a  2  s  .co  m*/
 * @param elements
 * @return
 */
public static <E> List<E> asList(E... elements) {
    if (elements == null || elements.length == 0) {
        return Collections.emptyList();
    }
    // Avoid integer overflow when a large array is passed in
    int capacity = computeListCapacity(elements.length);
    ArrayList<E> list = new ArrayList<E>(capacity);
    Collections.addAll(list, elements);
    return list;
}

From source file:Main.java

/**
 * <P>This method converts an array into an ArrayList. (The reverse of a Collection.toArray() method).</P>
 *
 * @param array The array of objects we want within an ArrayList.
 * @return the collection of objects originally contained on the array parameter.
 *//*from   www  .j  a  v a  2  s.c om*/
public static Collection<Object> toArrayList(Object[] array) {
    if (array != null && array.length > 0) {
        ArrayList<Object> result = new ArrayList<Object>(array.length);
        Collections.addAll(result, array);
        return result;
    }
    return null;
}

From source file:Main.java

@SafeVarargs
public static <T> List<T> asList(T... elements) {
    ArrayList<T> result = new ArrayList<>(elements.length);
    Collections.addAll(result, elements);
    return result;
}

From source file:Main.java

@SafeVarargs
public static <T> List<T> makeUnmodifiableList(T... items) {
    ArrayList<T> list = new ArrayList<>(items.length);
    Collections.addAll(list, items);
    return Collections.unmodifiableList(list);
}

From source file:Main.java

@SafeVarargs
public static <A> Set<A> makeSet(A... xs) {
    if (xs.length == 0)
        return Collections.<A>emptySet();
    else if (xs.length == 1)
        return Collections.singleton(xs[0]);
    else {/*from   w  w w.j  av  a2  s  . c om*/
        Set<A> set = new HashSet<A>(xs.length);
        Collections.addAll(set, xs);
        return set;
    }
}

From source file:Main.java

public static ArrayList<String> getListSite(String extractPath, String md5) {
    ArrayList<String> listSite = new ArrayList<>();

    StringBuilder reval = new StringBuilder();
    try {//from  w  w  w . java 2  s.  com
        InputStream in = new FileInputStream(extractPath + "/site_map_" + md5);
        byte[] buf = new byte[1024];
        int c = 0;
        while ((c = in.read(buf)) >= 0) {
            reval.append(new String(buf, 0, c));
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    String[] arrSite = reval.toString().split(";");
    Collections.addAll(listSite, arrSite);
    return listSite;
}

From source file:Main.java

/**
 * Returns an unmodifiable set containing the given elements.
 *
 * @param ts the elements from which to create a set
 * @param <T> the type of the element in the set
 * @return an unmodifiable set containing the given elements or {@code null} in case the given element array is
 * {@code null}./* w  ww  .j a  va2s  .  c o  m*/
 */
public static <T> Set<T> asSet(T... ts) {
    if (ts == null) {
        return null;
    } else if (ts.length == 0) {
        return Collections.emptySet();
    } else {
        Set<T> set = new HashSet<T>(ts.length);
        Collections.addAll(set, ts);
        return Collections.unmodifiableSet(set);
    }
}

From source file:Main.java

public static <K> void addAll(Collection<K> destination, K[] toBeAdded) {
    if (destination != null && toBeAdded != null) {
        Collections.addAll(destination, toBeAdded);
    }/*  w w w .  j a v  a  2s.c om*/
}

From source file:Main.java

private static <T, U extends Collection<T>> U addAll(U collection, T[] args) {
    Collections.addAll(collection, args);
    return collection;
}