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:com.taobao.datax.engine.schedule.JarLoader.java

private static URL[] getUrls(String[] paths) {
    if (null == paths || 0 == paths.length) {
        throw new IllegalArgumentException("Paths cannot be empty .");
    }/*from w  w w.  j  a  va 2  s  .  co  m*/

    List<URL> urls = new ArrayList<URL>();
    for (String path : paths) {
        urls.addAll(Arrays.asList(getUrl(path)));
    }

    return urls.toArray(new URL[0]);
}

From source file:com.theoryinpractise.coffeescript.FileUtilities.java

/**
 * Convenience Method for turning a FileSet into a list of files to be processed
 */// www .  j  a  v a2  s. c  o m
public static List<File> fileSetToFileList(FileSet fileset) throws IOException {
    List<File> files = Lists.newArrayList();

    files.addAll(FileUtilities.getFilesFromFileSet(fileset));

    return files;
}

From source file:Main.java

public static void compareList(List<? extends Object> origin, List<? extends Object> current,
        List<Object> added, List<Object> removed) {
    if (origin == null) {
        if (current != null) {
            added.addAll(current);
        }/* w ww .ja  v  a2 s  . c  o m*/
        return;
    }

    if (current == null) {
        if (origin != null) {
            removed.addAll(origin);
        }
        return;
    }

    Set<Object> originSet = new HashSet<Object>(origin);

    for (Object eachValue : current) {
        if (!originSet.remove(eachValue)) {
            added.add(eachValue);
        }
    }

    removed.addAll(originSet);
}

From source file:Main.java

/**
 * Removes the duplicates by modifying the source list and keeping the order of the elements.
 *
 * @param <T>/*from ww w  .j a  va 2s  . c  o m*/
 *            the generic type
 * @param list
 *            the list
 * @return the same object as the argument
 */
public static <T> List<T> removeDuplicates(List<T> list) {
    Set<T> temp = createLinkedHashSet(list.size());
    temp.addAll(list);
    list.clear();
    list.addAll(temp);
    return list;
}

From source file:Main.java

/**
 * concatenates the given Collections to one Collection.
 * @param iterable iterates thru the collections to be merged into one.
 * @return the elements of all given Collections concatenated into one Collection.
 * @postcondition result != null/*from   w ww . j  a  v a2  s.  c  o  m*/
 */
public static <E> List<E> concatAll(Iterable<? extends Collection<? extends E>> iterable) {
    final List<E> result = new ArrayList<E>();
    for (Collection<? extends E> coll : iterable) {
        result.addAll(coll);
    }
    assert result != null;
    return result;
}

From source file:Main.java

/**
 * Given a list of elements of type <T>, remove the duplicates from the list in place
 * /*  w  w w  .  j  a v a  2  s.  c o  m*/
 * @param <T>
 * @param list
 */
public static <T> void removeDuplicates(List<T> list) {
    // uses LinkedHashSet to keep the order
    Set<T> set = new LinkedHashSet<T>(list);

    list.clear();
    list.addAll(set);
    if (list instanceof ArrayList) {
        ((ArrayList<T>) list).trimToSize();
    }
}

From source file:Main.java

public static <T> List<T> circleSubList(List<T> srcList, int position, int count) {
    if (srcList == null || srcList.size() == 0) {
        return Collections.emptyList();
    }// ww  w  .  jav a2  s  . com
    position = position < 0 ? 0 : position;
    count = count > srcList.size() ? srcList.size() : count;
    if (position > srcList.size() - 1) {
        return srcList.subList(0, count);
    }
    if (position + count <= srcList.size()) {
        return srcList.subList(position, (position + count));
    }
    List<T> fList = srcList.subList(position, srcList.size());
    List<T> eList = srcList.subList(0, count - srcList.size() + position);
    fList.addAll(eList);
    return fList;
}

From source file:es.emergya.consultas.PatrullaConsultas.java

public static String[] getAllFilter() {
    List<String> res = new ArrayList<String>();
    res.add("");/* ww  w  .  ja v  a 2s. com*/
    res.addAll(patrullaHome.getAllNames());
    return res.toArray(new String[0]);
}

From source file:javaphpmysql.JavaPHPMySQL.java

public static void sendGet() {
    //Creamos un objeto JSON
    JSONObject jsonObj = new JSONObject();
    //Aadimos el nombre, apellidos y email del usuario
    jsonObj.put("nombre", nombre);
    jsonObj.put("apellidos", apellidos);
    jsonObj.put("email", email);
    //Creamos una lista para almacenar el JSON
    List l = new LinkedList();
    l.addAll(Arrays.asList(jsonObj));
    //Generamos el String JSON
    String jsonString = JSONValue.toJSONString(l);
    System.out.println("JSON GENERADO:");
    System.out.println(jsonString);
    System.out.println("");

    try {//from  ww  w  .j  a v a2  s.c om
        //Codificar el json a URL
        jsonString = URLEncoder.encode(jsonString, "UTF-8");
        //Generar la URL
        String url = SERVER_PATH + "listenGet.php?json=" + jsonString;
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        // optional default is GET
        con.setRequestMethod("GET");

        //add request header
        con.setRequestProperty("User-Agent", USER_AGENT);

        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'GET' request to URL : " + url);
        System.out.println("Response Code : " + responseCode);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        //print result
        System.out.println(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.dv8tion.jda.player.Playlist.java

public static Playlist getPlaylist(String url) {
    List<String> infoArgs = new LinkedList<>();
    infoArgs.addAll(YOUTUBE_DL_PLAYLIST_ARGS);
    infoArgs.add("--"); //Url separator. Deals with YT ids that start with --
    infoArgs.add(url);// www .  j ava  2  s.  com

    //Fire up Youtube-dl and get all sources from the provided url.
    List<AudioSource> sources = new ArrayList<>();
    Scanner scan = null;
    try {
        Process infoProcess = new ProcessBuilder().command(infoArgs).start();
        byte[] infoData = IOUtils.readFully(infoProcess.getInputStream(), -1, false);
        if (infoData == null || infoData.length == 0)
            throw new NullPointerException(
                    "The YT-DL playlist process resulted in a null or zero-length INFO!");

        String sInfo = new String(infoData);
        scan = new Scanner(sInfo);

        JSONObject source = new JSONObject(scan.nextLine());
        if (source.has("_type"))//Is a playlist
        {
            sources.add(new RemoteSource(source.getString("url")));
            while (scan.hasNextLine()) {
                source = new JSONObject(scan.nextLine());
                sources.add(new RemoteSource(source.getString("url")));
            }
        } else //Single source link
        {
            sources.add(new RemoteSource(source.getString("webpage_url")));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (scan != null)
            scan.close();
    }

    //Now that we have all the sources we can create our Playlist object.
    Playlist playlist = new Playlist("New Playlist");
    playlist.sources = sources;
    return playlist;
}