Example usage for java.util ArrayList addAll

List of usage examples for java.util ArrayList addAll

Introduction

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

Prototype

public 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.

Usage

From source file:de.mpg.escidoc.services.transformation.Util.java

/**
 * Queries the CoNE service and transforms the result into a DOM node.
 * //from ww  w .  ja v a 2  s  .com
 * @param model The type of object (e.g. "persons")
 * @param name The query string.
 * @param ou Specialty for persons
 * @param coneSession A JSESSIONID to not produce a new session with each call.
 * @return A DOM node containing the results.
 */
public static Node queryConeExactWithIdentifier(String model, String identifier, String ou) {
    DocumentBuilder documentBuilder;

    try {
        logger.info("queryConeExactWithIdentifier: " + model + " identifier: " + identifier + " ou: " + ou);

        documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder();

        Document document = documentBuilder.newDocument();
        Element element = document.createElement("cone");
        document.appendChild(element);

        String queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/query?format=jquery&dc:identifier/" + URLEncoder.encode("rdf:value", "UTF-8") + "="
                + URLEncoder.encode("\"" + identifier + "\"", "UTF-8") + "&"
                + URLEncoder.encode("escidoc:position/eprints:affiliatedInstitution", "UTF-8") + "="
                + URLEncoder.encode("\"*" + ou + "*\"", "UTF-8");
        String detailsUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/resource/$1?format=rdf";
        HttpClient client = new HttpClient();
        client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        GetMethod method = new GetMethod(queryUrl);

        String coneSession = getConeSession();

        if (coneSession != null) {
            method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
        }
        ProxyHelper.executeMethod(client, method);
        if (logger.isDebugEnabled()) {
            logger.debug("CoNE query: " + queryUrl + " returned " + method.getResponseBodyAsString());
        }
        if (method.getStatusCode() == 200) {
            ArrayList<String> results = new ArrayList<String>();
            results.addAll(Arrays.asList(method.getResponseBodyAsString().split("\n")));
            Set<String> oldIds = new HashSet<String>();
            for (String result : results) {
                if (!"".equals(result.trim())) {
                    String id = result.split("\\|")[1];
                    if (!oldIds.contains(id)) {
                        // TODO "&redirect=true" must be reinserted again
                        GetMethod detailMethod = new GetMethod(id + "?format=rdf&eSciDocUserHandle="
                                + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8")));
                        detailMethod.setFollowRedirects(true);

                        ProxyHelper.setProxy(client, detailsUrl.replace("$1", id));
                        client.executeMethod(detailMethod);
                        // TODO "&redirect=true" must be reinserted again
                        if (logger.isDebugEnabled()) {
                            logger.debug("CoNE query: " + id + "?format=rdf&eSciDocUserHandle="
                                    + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8"))
                                    + " returned " + detailMethod.getResponseBodyAsString());
                        }
                        if (detailMethod.getStatusCode() == 200) {
                            Document details = documentBuilder.parse(detailMethod.getResponseBodyAsStream());
                            element.appendChild(document.importNode(details.getFirstChild(), true));
                        } else {
                            logger.error("Error querying CoNE: Status " + detailMethod.getStatusCode() + "\n"
                                    + detailMethod.getResponseBodyAsString());
                        }
                        oldIds.add(id);
                    }
                }
            }
        } else {
            logger.error("Error querying CoNE: Status " + method.getStatusCode() + "\n"
                    + method.getResponseBodyAsString());
        }
        return document;
    } catch (Exception e) {
        logger.error("Error querying CoNE service. This is normal during unit tests. "
                + "Otherwise it should be clarified if any measures have to be taken.", e);
        return null;
        //throw new RuntimeException(e);
    }
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?Arrays.asList(),ArrayList/* w  ww .j av  a 2s. c o  m*/
 * ????
 */
public static <T> List<T> asList(T... args) {
    ArrayList<T> list = new ArrayList<T>(args.length + 16);
    list.addAll(Arrays.asList(args));
    return list;
}

From source file:nl.tue.gale.ae.config.GaleContextLoader.java

@Override
protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext ac) {
    super.customizeContext(sc, ac);
    ArrayList<String> locations = new ArrayList<String>();
    locations.addAll(Arrays.asList(ac.getConfigLocations()));
    findLocations(sc, locations);/* w w  w.j  a  v  a 2  s  . c  o  m*/
    ac.setConfigLocations(locations.toArray(new String[] {}));
}

From source file:Model.Picture.java

private static ArrayList<String> enterUploadedData(String fileName) {
    ArrayList<String> errors = new ArrayList<String>();

    try {// w ww  .  j a  v a2s.  co  m
        FileInputStream file = new FileInputStream(Constants.TEMP_DIR + fileName);
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet = workbook.getSheetAt(0);

        int rowStart = sheet.getFirstRowNum();
        int rowEnd = sheet.getLastRowNum() + 1;
        int colStart = sheet.getRow(rowStart).getFirstCellNum();
        int colEnd = sheet.getRow(rowStart).getLastCellNum();

        int[] indices = ExcelTools.getColumnIndices(colStart, colEnd, sheet.getRow(rowStart));
        if (Tools.arrayContains(indices, -1)) {
            errors.add(Constants.IMPROPER_EXCEL_FORMAT);
            return errors;
        }

        errors.addAll(ExcelTools.readFile(indices, sheet, rowStart + 1, rowEnd));

    } catch (IOException e) {
        e.printStackTrace(System.out);
    }
    return errors;
}

From source file:com.subgraph.vega.internal.analysis.urls.HtmlUrlExtractor.java

private List<URI> extractUrlsFromDocument(Document document) {
    final ArrayList<URI> uris = new ArrayList<URI>();
    uris.addAll(extractURIs(document, "a[href]", "abs:href"));
    uris.addAll(extractURIs(document, "[src]", "abs:src"));
    uris.addAll(extractURIs(document, "link[href]", "abs:href"));
    return uris;/*from  w w  w.  ja  v a 2  s.  c o m*/
}

From source file:org.mifos.client.repository.InMemoryClientDao.java

@Override
public List<Client> getAll() {
    ArrayList<Client> clientList = new ArrayList<Client>();
    clientList.addAll(clients.values());
    return clientList;
}

From source file:dm_p2.DBSCAN.java

public static ArrayList<cluster> DBSCAN(double eps, int MinPts) {
    ArrayList<cluster> clist = new ArrayList<cluster>();
    int c = 1;/*from   w  ww  . java 2  s .  c  o  m*/
    for (int i = 0; i < genelist.size(); i++) {
        if (genelist.get(i).isVisited() == 0) {
            genelist.get(i).Visited(1);
            ArrayList<gene> npts = regionQuery(genelist.get(i), eps);
            if (npts.size() < MinPts) {
                genelist.get(i).addcl("NOISE");
            } else {
                cluster cl = new cluster(c);
                genelist.get(i).setclusid(c);
                cl.addtocl(genelist.get(i));
                for (int k = 0; k < npts.size(); k++) {
                    if (npts.get(k).isVisited() == 0
                            || (npts.get(k).isVisited() == 1 && npts.get(k).getcl().compareTo("NOISE") == 0)) {
                        npts.get(k).Visited(1);
                        ArrayList<gene> npts1 = regionQuery(npts.get(k), eps);
                        if (npts1.size() >= MinPts) {
                            npts.addAll(npts1);
                        }
                        if (npts.get(k).getclusid() == 0) {
                            npts.get(k).setclusid(c);
                            cl.addtocl(npts.get(k));
                        }
                    }
                }
                clist.add(cl);
                c++;

            }
        }
    }
    return clist;
}

From source file:org.openmrs.module.chartsearch.fragment.controller.ManagePreferencesFragmentController.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public void controller(FragmentModel model, UiUtils ui) {
    AllColors allColors = new AllColors();
    String[] allColorsArray = new String[allColors.ALLCOLORSLENGTH];
    ArrayList list = new ArrayList(Arrays.asList(allColors));

    list.addAll(Arrays.asList(allColors.REDBASEDCOLORS));
    list.addAll(Arrays.asList(allColors.GREENBASEDCOLORS));
    list.addAll(Arrays.asList(allColors.BLUEBASEDCOLORS));
    for (int i = 0; i < allColorsArray.length; i++) {
        if (list.get(i) instanceof String) {
            allColorsArray[i] = (String) list.get(i);
        }/*www .  java  2 s .  c o m*/
    }
    allColors.printAllColors(true);

    model.put("preferences", GeneratingJson.generateRightMatchedPreferencesJSON().toString());
    model.put("daemonPreferences", GeneratingJson.generateDaemonPreferencesJSON().toString());
    model.put("categoryFilters", ui.escapeJs(GeneratingJson.generateAllCategoriesJSON().toString()));
    model.put("allColors", allColorsArray);
    model.put("redBasedColors", allColors.REDBASEDCOLORS);
    model.put("greenBasedColors", allColors.GREENBASEDCOLORS);
    model.put("blueBasedColors", allColors.BLUEBASEDCOLORS);
    model.put("personalColorsNotes", cache.fetchPersonalNotesColors());
}

From source file:com.logicmonitor.ft.jmxstat.JMXStatMain.java

/**
 * @param args : arguments array//from   www  . j  av  a2  s  . c om
 * @return Run Parameter
 */
private static RunParameter ARGSAnalyser(String[] args) {

    Options options = new Options();
    options.addOption(new Option("h", "help", false, "show this help message"))
            .addOption(new Option("u", true, "User name for remote process"))
            .addOption(new Option("p", true, "Password for remote process"))
            .addOption(new Option("f", true, "Path to the configure file"))
            .addOption(new Option("t", true, "Exit after scanning jmx-paths n times"))
            .addOption(new Option("i", true, "Interval between two scan tasks, unit is second"))
            .addOption(new Option("a", false, "Show alias names instead of jmx paths"));

    CommandLineParser parser = new BasicParser();
    RunParameter runParameter = new RunParameter();
    ArrayList<JMXInPath> inputtedPaths = new ArrayList<JMXInPath>();
    try {
        CommandLine cli = parser.parse(options, args);
        if (args.length == 0 || cli.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("jmxstat jmxURL [jmx path lists]", "To view statuses of jmx paths:", options,
                    "@Support by LogicMonitor", true);
            exit(0);
        }

        runParameter.setValid(true);
        if (cli.hasOption('a')) {
            runParameter.setShowAliasTitle(true);
        }
        if (cli.hasOption('f')) {
            List<JMXInPath> paths_from_file = getPathsFromFile(cli.getOptionValue('f'));
            inputtedPaths.addAll(paths_from_file);
        }
        if (cli.hasOption('t')) {
            try {
                int times = Integer.valueOf(cli.getOptionValue('t'));
                if (times < 0)
                    System.out.println("The argument after <-t> is useless here since it's a negative number.");
                else
                    runParameter.setTimes(times);
            } catch (Exception e) {
                runParameter.setValid(false);
                runParameter.setValidInfo(
                        runParameter.getValidInfo() + "Argument after <-t> should be an integer\n");
            }
        }
        if (cli.hasOption('u')) {
            runParameter.setUsername(cli.getOptionValue('u'));
        }
        if (cli.hasOption('p')) {
            runParameter.setPassword(cli.getOptionValue('p'));
        }
        if (cli.hasOption('i')) {
            try {
                int interval = Integer.valueOf(cli.getOptionValue('i'));
                if (interval < 0)
                    System.err.println("The interval value is negative! Using default set!");
                else {
                    runParameter.setInterval(interval);
                }
            } catch (Exception e) {
                runParameter.setValid(false);
                runParameter.setValidInfo(
                        runParameter.getValidInfo() + "Argument after <-i> should be an integer\n");
            }
        }
        List<String> others = cli.getArgList();
        boolean jmxurl_found = false;
        for (String other : others) {
            if (other.toLowerCase().startsWith("service:jmx")) {
                if (jmxurl_found) {
                    runParameter.setValid(false);
                    runParameter.setValidInfo(runParameter.getValidInfo() + "multiple jmxurl found\n");
                    return runParameter;
                } else {
                    jmxurl_found = true;
                    runParameter.setSurl(other.toLowerCase());
                }
            } else {
                inputtedPaths.add(new JMXInPath(other));
            }
        }
        if (!jmxurl_found) {
            runParameter.setValid(false);
            runParameter.setValidInfo(runParameter.getValidInfo()
                    + "No jmxurl found. The jmxurl should start with \"service:jmx\" \n");
        }
    } catch (ParseException e) {
        runParameter.setValid(false);
        runParameter.setValidInfo(runParameter.getValidInfo() + "Exception caught while parse arguments!\n");
    }

    if (inputtedPaths.isEmpty()) {
        runParameter.setValid(false);
        runParameter.setValidInfo(runParameter.getValidInfo() + "No jmx paths inputted");
    } else {
        runParameter.setPaths(inputtedPaths);
    }
    return runParameter;
}

From source file:de.mpg.escidoc.services.transformation.Util.java

/**
 * Queries the CoNE service and transforms the result into a DOM node.
 * //from   w w  w.  j  a v a  2  s .com
 * @param model The type of object (e.g. "persons")
 * @param name The query string.
 * @param ou Specialty for persons
 * @param coneSession A JSESSIONID to not produce a new session with each call.
 * @return A DOM node containing the results.
 */
public static Node queryConeExact(String model, String name, String ou) {
    DocumentBuilder documentBuilder;

    try {
        logger.info("queryConeExact: " + model + " name: " + name + " ou: " + ou);

        documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder();

        Document document = documentBuilder.newDocument();
        Element element = document.createElement("cone");
        document.appendChild(element);

        String queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/query?format=jquery&" + URLEncoder.encode("dc:title", "UTF-8") + "="
                + URLEncoder.encode("\"" + name + "\"", "UTF-8") + "&"
                + URLEncoder.encode("escidoc:position/eprints:affiliatedInstitution", "UTF-8") + "="
                + URLEncoder.encode("\"*" + ou + "*\"", "UTF-8");
        String detailsUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/resource/$1?format=rdf";
        HttpClient client = new HttpClient();
        client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        GetMethod method = new GetMethod(queryUrl);

        String coneSession = getConeSession();

        if (coneSession != null) {
            method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
        }
        ProxyHelper.executeMethod(client, method);
        if (logger.isDebugEnabled()) {
            logger.debug("CoNE query: " + queryUrl + " returned " + method.getResponseBodyAsString());
        }
        if (method.getStatusCode() == 200) {
            ArrayList<String> results = new ArrayList<String>();
            results.addAll(Arrays.asList(method.getResponseBodyAsString().split("\n")));
            queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model + "/query?format=jquery&"
                    + URLEncoder.encode("dcterms:alternative", "UTF-8") + "="
                    + URLEncoder.encode("\"" + name + "\"", "UTF-8") + "&"
                    + URLEncoder.encode("escidoc:position/eprints:affiliatedInstitution", "UTF-8") + "="
                    + URLEncoder.encode("\"*" + ou + "*\"", "UTF-8");
            client = new HttpClient();
            method = new GetMethod(queryUrl);
            if (coneSession != null) {
                method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
            }
            ProxyHelper.executeMethod(client, method);
            if (logger.isDebugEnabled()) {
                logger.debug("CoNE query: " + queryUrl + " returned " + method.getResponseBodyAsString());
            }
            if (method.getStatusCode() == 200) {
                results.addAll(Arrays.asList(method.getResponseBodyAsString().split("\n")));
                Set<String> oldIds = new HashSet<String>();
                for (String result : results) {
                    if (!"".equals(result.trim())) {
                        String id = result.split("\\|")[1];
                        if (!oldIds.contains(id)) {
                            // TODO "&redirect=true" must be reinserted again
                            GetMethod detailMethod = new GetMethod(id + "?format=rdf&eSciDocUserHandle="
                                    + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8")));
                            detailMethod.setFollowRedirects(true);

                            ProxyHelper.setProxy(client, detailsUrl.replace("$1", id));
                            client.executeMethod(detailMethod);
                            // TODO "&redirect=true" must be reinserted again
                            if (logger.isDebugEnabled()) {
                                logger.debug("CoNE query: " + id + "?format=rdf&eSciDocUserHandle="
                                        + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8"))
                                        + " returned " + detailMethod.getResponseBodyAsString());
                            }
                            if (detailMethod.getStatusCode() == 200) {
                                Document details = documentBuilder
                                        .parse(detailMethod.getResponseBodyAsStream());
                                element.appendChild(document.importNode(details.getFirstChild(), true));
                            } else {
                                logger.error("Error querying CoNE: Status " + detailMethod.getStatusCode()
                                        + "\n" + detailMethod.getResponseBodyAsString());
                            }
                            oldIds.add(id);
                        }
                    }
                }
            }
        } else {
            logger.error("Error querying CoNE: Status " + method.getStatusCode() + "\n"
                    + method.getResponseBodyAsString());
        }
        return document;
    } catch (Exception e) {
        logger.error("Error querying CoNE service. This is normal during unit tests. "
                + "Otherwise it should be clarified if any measures have to be taken.", e);
        return null;
        //throw new RuntimeException(e);
    }
}