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:javaphpmysql.JavaPHPMySQL.java

public static void sendPost() {
    //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   w w w  .j a  v a2 s .c  o  m*/
        //Codificar el json a URL
        jsonString = URLEncoder.encode(jsonString, "UTF-8");
        //Generar la URL
        String url = SERVER_PATH + "listenPost.php";
        //Creamos un nuevo objeto URL con la url donde queremos enviar el JSON
        URL obj = new URL(url);
        //Creamos un objeto de conexin
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        //Aadimos la cabecera
        con.setRequestMethod("POST");
        con.setRequestProperty("User-Agent", USER_AGENT);
        con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
        //Creamos los parametros para enviar
        String urlParameters = "json=" + jsonString;
        // Enviamos los datos por POST
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();
        //Capturamos la respuesta del servidor
        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + urlParameters);
        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);
        }
        //Mostramos la respuesta del servidor por consola
        System.out.println(response);
        //cerramos la conexin
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.obiba.mica.study.service.StudyService.java

public static <E> List<E> listAddAll(List<E> accumulator, List<E> list) {
    accumulator.addAll(list);
    return accumulator;
}

From source file:domainregistry.AdvancedSearch.java

public static Map<String, HypertyInstance> getHyperties(Map<String, String> parameters,
        Map<String, HypertyInstance> data) {
    Map<String, HypertyInstance> foundHyperties = new HashMap();

    for (Map.Entry<String, HypertyInstance> entry : data.entrySet()) {
        HypertyInstance hyperty = entry.getValue();

        List<String> dataSchemesTypes = map(hyperty.getDataSchemes(), SCHEMES_PREFIX);
        List<String> resourcesTypes = map(hyperty.getResources(), RESOURCES_PREFIX);

        List<String> hypertyParams = new ArrayList<String>(dataSchemesTypes);
        hypertyParams.addAll(resourcesTypes);
        Set hypertyParamsSet = new HashSet(hypertyParams);

        if (hypertyParamsSet.containsAll(new HashSet<String>(getQueryParams(parameters)))) {
            foundHyperties.put(entry.getKey(), hyperty);
        }/*from w ww  .j a  va2  s . c  o m*/
    }

    return foundHyperties;
}

From source file:io.spring.initializr.web.ui.UiController.java

private static Map<String, Object> mapDependency(DependencyItem item) {
    Map<String, Object> result = new HashMap<>();
    Dependency d = item.dependency;/*  ww  w.j av a2 s .  com*/
    result.put("id", d.getId());
    result.put("name", d.getName());
    result.put("group", item.group);
    if (d.getDescription() != null) {
        result.put("description", d.getDescription());
    }
    if (d.getWeight() > 0) {
        result.put("weight", d.getWeight());
    }
    if (!CollectionUtils.isEmpty(d.getKeywords()) || !CollectionUtils.isEmpty(d.getAliases())) {
        List<String> all = new ArrayList<>(d.getKeywords());
        all.addAll(d.getAliases());
        result.put("keywords", StringUtils.collectionToCommaDelimitedString(all));
    }
    return result;
}

From source file:Main.java

License:asdf

public static List<String> allPermutation(String permutation, String letters) {
    List<String> list = new ArrayList<>();
    if (letters.isEmpty()) {
        list.add(permutation);//from  www .j av a 2s.c o m
        return list;
    }

    for (int i = 0; i < letters.length(); i++) {
        list.addAll(allPermutation(permutation + letters.charAt(i), removeCharAt(i, letters)));
    }

    return list;
}

From source file:br.eti.danielcamargo.backend.common.utils.MessageUtils.java

public static Mensagem criarMensagemErro(String modulo, ValidationOccurrence occurrence) {
    String param1 = occurrence.getMessageKey();

    String msg = buscarChave(modulo, param1, occurrence.getParams());

    Serializable[] params = occurrence.getParams();
    List<Serializable> list = new ArrayList<>();
    if (params != null) {
        list.addAll(Arrays.asList(params));
    }/*ww  w .j  ava 2s .co m*/
    return new Mensagem(msg, NivelMensagem.ERRO, list);
}

From source file:domainregistry.AdvancedSearch.java

public static Map<String, DataObjectInstance> getDataObjects(Map<String, String> params,
        Map<String, DataObjectInstance> objects) {
    Map<String, DataObjectInstance> foundDataObjects = new HashMap();

    for (Map.Entry<String, DataObjectInstance> entry : objects.entrySet()) {
        DataObjectInstance dataObject = entry.getValue();

        List<String> resourcesTypes = map(dataObject.getResources(), RESOURCES_PREFIX);
        List<String> dataSchemesTypes = map(dataObject.getDataSchemes(), SCHEMES_PREFIX);

        List<String> dataObjectParams = new ArrayList<String>(dataSchemesTypes);
        dataObjectParams.addAll(resourcesTypes);
        Set dataObjectsParamsSet = new HashSet(dataObjectParams);

        if (dataObjectsParamsSet.containsAll(new HashSet<String>(getQueryParams(params)))) {
            foundDataObjects.put(entry.getKey(), dataObject);
        }/*from   w  w w .  j  a  v  a 2 s .c om*/
    }

    return foundDataObjects;
}

From source file:Main.java

public static <E> Collection<List<E>> selectExactly(List<E> original, int nb) {
    if (nb < 0) {
        throw new IllegalArgumentException();
    }/*  w w  w  . jav a  2  s  . c o  m*/
    if (nb == 0) {
        return Collections.emptyList();
    }
    if (nb == 1) {
        final List<List<E>> result = new ArrayList<List<E>>();
        for (E element : original) {
            result.add(Collections.singletonList(element));
        }
        return result;

    }
    if (nb > original.size()) {
        return Collections.emptyList();
    }
    if (nb == original.size()) {
        return Collections.singletonList(original);
    }
    final List<List<E>> result = new ArrayList<List<E>>();

    for (List<E> subList : selectExactly(original.subList(1, original.size()), nb - 1)) {
        final List<E> newList = new ArrayList<E>();
        newList.add(original.get(0));
        newList.addAll(subList);
        result.add(Collections.unmodifiableList(newList));
    }
    result.addAll(selectExactly(original.subList(1, original.size()), nb));

    return Collections.unmodifiableList(result);
}

From source file:br.eti.danielcamargo.backend.common.utils.MessageUtils.java

public static Mensagem criarMensagemErroValidacao(String modulo, ValidationOccurrence occurrence) {
    String param1 = occurrence.getMessageKey();

    String campo = buscarChave(modulo, param1, occurrence.getParams());

    String detalhe = buscarChave(modulo, "common.validation-error", param1, campo);

    Serializable[] params = occurrence.getParams();
    List<Serializable> list = new ArrayList<>();
    if (params != null) {
        list.addAll(Arrays.asList(params));
    }// w  w  w  .j  a v  a 2  s.co m
    return new Mensagem(detalhe, NivelMensagem.ERRO, list);
}

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

public static List<String> getAllNames() {
    List<String> res = new ArrayList<String>();
    try {/*from  ww  w.ja  va 2  s  . c om*/
        res.addAll(rolHome.getAllString());
    } catch (Throwable t1) {
        log.error(t1, t1);
    }

    return res;
}