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:edu.wustl.cab2b.server.queryengine.QueryOperations.java

private static Collection<ForeignAssociation> getForeignAssociations(ForeignAssociation faa) {
    ArrayList<ForeignAssociation> fas = new ArrayList<ForeignAssociation>();

    gov.nih.nci.cagrid.dcql.Object fo = faa.getForeignObject();
    Group fog = fo.getGroup();/* ww  w. j a  v a 2 s . co  m*/

    if (fog != null) {
        Group[] gr1 = new Group[1];
        gr1[0] = fog;
        fas.addAll(getForeignAssociations(gr1));
    }

    ForeignAssociation fofa = fo.getForeignAssociation();
    if (fofa != null) {
        fas.add(fofa);

        fas.addAll(getForeignAssociations(fofa));
    }

    return fas;
}

From source file:edu.umass.cs.utils.Util.java

public static ArrayList<String> recursiveFind(String dir, String regex) {
    ArrayList<String> matches = new ArrayList<String>();
    for (File f : new File(dir).listFiles()) {
        if (f.toString().matches(regex))
            matches.add(f.toString());//from   w w w .  j av a 2s  .  c om
        if (f.isDirectory())
            matches.addAll(recursiveFind(f.toString(), regex));
    }
    return matches;
}

From source file:edu.wustl.cab2b.server.queryengine.QueryOperations.java

private static Collection<ForeignAssociation> getForeignAssociations(Group[] g) {
    ArrayList<ForeignAssociation> fas = new ArrayList<ForeignAssociation>();
    for (int y = 0; y < g.length; y++) {

        ForeignAssociation[] faa = g[y].getForeignAssociation();

        for (int x = 0; x < faa.length; x++) {
            fas.add(faa[x]);/*from  ww  w  . jav a  2 s. co m*/
            fas.addAll(getForeignAssociations(faa[x]));
        }

        Group[] g2 = g[y].getGroup();

        if (g2.length > 0) {
            fas.addAll(getForeignAssociations(g2));
        }
    }
    return fas;

}

From source file:com.clustercontrol.accesscontrol.factory.RoleSelector.java

/**
 * ???<BR>/*from   w w w. j  a  v  a 2s  . c om*/
 * 
 * @return ??
 * @throws HinemosUnknown
 */
public static ArrayList<ObjectPrivilegeInfo> getObjectPrivilegeInfoList(ObjectPrivilegeFilterInfo filter) {

    ArrayList<ObjectPrivilegeInfo> list = new ArrayList<ObjectPrivilegeInfo>();
    List<ObjectPrivilegeInfo> objectPrivileges = null;

    if (filter == null) {
        // ?
        objectPrivileges = QueryUtil.getAllObjectPrivilege();
    } else {
        // ?
        objectPrivileges = QueryUtil.getAllObjectPrivilegeByFilter(filter.getObjectType(), filter.getObjectId(),
                filter.getRoleId(), filter.getObjectPrivilege());
    }

    if (objectPrivileges != null && objectPrivileges.size() > 0) {
        list.addAll(objectPrivileges);
    }
    return list;
}

From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java

/**
 * Launch the download of the courses list and store them in the database.
 * /*from www.ja v  a 2  s. c om*/
 * @param context
 *          Application context.
 * @param username
 *          UCL global user identifier.
 * @param password
 *          UCL password.
 * @param end
 *          Runnable to be executed at the end of the download.
 * @param mHandler
 *          Handler to manage messages and threads.
 *          
 */
public static void downloadCoursesFromUCLouvain(final LLNCampusActivity context, final String username,
        final String password, final Runnable end, final Handler mHandler) {
    Time t = new Time();
    t.setToNow();
    int year = t.year;
    // A new academic year begin in September (8th month on 0-based count).
    if (t.month < 8) {
        year--;
    }
    final int academicYear = year;

    mHandler.post(new Runnable() {

        public void run() {

            final ProgressDialog mProgress = new ProgressDialog(context);
            mProgress.setCancelable(false);
            mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgress.setMax(100);
            mProgress.setMessage(context.getString(R.string.connection));
            mProgress.show();

            new Thread(new Runnable() {
                /**
                 * Set the progress to the value n and show the message nextStep
                 * @param n
                 *          The progress value.
                 * @param nextStep
                 *          The message to show (indicate the next step to be processed).
                 */
                public void progress(final int n, final String nextStep) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(n);
                            mProgress.setMessage(nextStep);
                        }
                    });
                    Log.d("UCLouvain", nextStep);
                }

                /**
                 * Notify to the user an error.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void sendError(String msg) {
                    notify(context.getString(R.string.error) + " :" + msg);
                    mProgress.cancel();
                }

                /**
                 * Notify to the user a message.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void notify(final String msg) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            context.notify(msg);
                        }
                    });
                }

                public void run() {
                    progress(0, context.getString(R.string.connection_ucl));
                    UCLouvain uclouvain = new UCLouvain(username, password);

                    progress(20, context.getString(R.string.fetch_info));
                    ArrayList<Offer> offers = uclouvain.getOffers(academicYear);

                    if (offers == null || offers.isEmpty()) {
                        sendError(context.getString(R.string.error_academic_year) + academicYear);
                        return;
                    }

                    int i = 40;
                    ArrayList<Course> courses = new ArrayList<Course>();
                    for (Offer o : offers) {
                        progress(i, context.getString(R.string.get_courses) + o.getOfferName());
                        ArrayList<Course> offerCourses = uclouvain.getCourses(o);
                        if (offerCourses != null && !offerCourses.isEmpty()) {
                            courses.addAll(offerCourses);
                        } else {
                            Log.e("CoursListEditActivity", "Error : No course for offer [" + o.getOfferCode()
                                    + "] " + o.getOfferName());
                        }
                        i += (int) (30. / offers.size());
                    }

                    if (courses.isEmpty()) {
                        sendError(context.getString(R.string.courses_empty));
                        return;
                    }

                    // Remove old courses.
                    progress(70, context.getString(R.string.cleaning_db));
                    LLNCampus.getDatabase().delete("Courses", "", null);
                    LLNCampus.getDatabase().delete("Horaire", "", null);

                    // Add new data.
                    i = 80;
                    for (Course c : courses) {
                        progress(i, context.getString(R.string.add_courses_db));
                        ContentValues cv = new ContentValues();
                        cv.put("CODE", c.getCourseCode());
                        cv.put("NAME", c.getCoursName());

                        LLNCampus.getDatabase().insert("Courses", cv);
                        i += (int) (20. / courses.size());
                    }

                    progress(100, context.getString(R.string.end));
                    mProgress.cancel();
                    mHandler.post(end);
                }
            }).start();
        }
    });
}

From source file:cz.cas.lib.proarc.common.export.cejsh.CejshBuilder.java

/**
 * Lists all files that should be part of a zip. Folder entries are not part of the list.
 * See issue #413.//from  www. ja v a2  s.c  om
 * @param folder a folder to scan
 * @return the list of files
 */
private static ArrayList<File> listZipFiles(File folder) {
    ArrayList<File> files = new ArrayList<File>();
    ArrayList<File> subfiles = new ArrayList<File>();
    for (File file : folder.listFiles()) {
        if (file.isFile()) {
            files.add(file);
        } else if (file.isDirectory()) {
            subfiles.addAll(listZipFiles(file));
        }
    }
    files.addAll(subfiles);
    return files;
}

From source file:de.mpg.escidoc.services.common.util.Util.java

/**
 * Queries the CoNE service and transforms the result into a DOM node.
 * /*from   w ww  . j a va2  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 {
        System.out.println("queryConeExact: " + model);

        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/rdf:value=\"" + URLEncoder.encode(identifier, "UTF-8")
                + "\"&escidoc:position/eprints:affiliatedInstitution=" + URLEncoder.encode(ou, "UTF-8") + "";
        String detailsUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/resource/$1?format=rdf";
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(queryUrl);

        String coneSession = getConeSession();

        if (coneSession != null) {
            method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
        }
        ProxyHelper.executeMethod(client, method);
        logger.info("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)) {
                        GetMethod detailMethod = new GetMethod(id + "?format=rdf&eSciDocUserHandle=" + "TODO");

                        ProxyHelper.setProxy(client, detailsUrl.replace("$1", id));
                        client.executeMethod(detailMethod);
                        logger.info("CoNE query: " + id + "?format=rdf&eSciDocUserHandle=" + "TODO"
                                + " 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.");
        return null;
        //throw new RuntimeException(e);
    }
}

From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java

/**
 * Check whether or not a trust path exists between the supplied X.509
 * certificate and and the supplied keystores based on the trusted
 * certificates contained therein, ie that a chain of trust exists between
 * the supplied certificate and a self-signed trusted certificate in the
 * KeyStores./*from  ww w  . ja  v  a 2s .  c  o m*/
 *
 * @return The trust chain, or null if trust could not be established
 * @param cert
 *            The certificate
 * @param keyStores
 *            The KeyStores
 * @throws CryptoException
 *             If there is a problem establishing trust
 */
public static X509Certificate[] establishTrust(X509Certificate cert, KeyStore keyStores[])
        throws CryptoException {
    ArrayList<X509Certificate> ksCerts = new ArrayList<X509Certificate>();

    for (int i = 0; i < keyStores.length; i++) {
        ksCerts.addAll(extractCertificates(keyStores[i]));
    }

    return establishTrust(cert, ksCerts);
}

From source file:Main.java

public static List<Node> getNodes(Node node, String path) {
    ArrayList nodeList = new ArrayList();

    ArrayList pathList = new ArrayList();
    String[] pathArray = path.split("/");
    for (int i = 0; i < pathArray.length; i++) {
        if (pathArray[i].equals(""))
            continue;
        pathList.add(pathArray[i]);/*from   w  w  w. jav  a2s.co  m*/
    }

    for (int i = 0; i < pathList.size(); i++) {
        StringBuffer restPath = new StringBuffer();
        for (int k = i + 1; k < pathList.size(); k++) {
            restPath.append("/").append((String) pathList.get(k));
        }

        for (int j = 0; j < node.getChildNodes().getLength(); j++) {
            if (!node.getChildNodes().item(j).getNodeName().equals(pathList.get(i)))
                continue;
            if (restPath.length() == 0) {
                nodeList.add(node.getChildNodes().item(j));
            } else {
                nodeList.addAll(getNodes(node.getChildNodes().item(j), restPath.toString()));
            }
        }

    }

    return nodeList;
}

From source file:de.mpg.escidoc.services.common.util.Util.java

/**
 * Queries the CoNE service and transforms the result into a DOM node.
 * /*from   ww  w.ja  va  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 {
        System.out.println("queryConeExact: " + model);

        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:title=\"" + URLEncoder.encode(name, "UTF-8")
                + "\"&escidoc:position/eprints:affiliatedInstitution=" + URLEncoder.encode(ou, "UTF-8") + "";
        String detailsUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/resource/$1?format=rdf";
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(queryUrl);

        String coneSession = getConeSession();

        if (coneSession != null) {
            method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
        }
        ProxyHelper.executeMethod(client, method);
        logger.info("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&dcterms:alternative=\"" + URLEncoder.encode(name, "UTF-8")
                    + "\"&escidoc:position/eprints:affiliatedInstitution=" + URLEncoder.encode(ou, "UTF-8");
            client = new HttpClient();
            method = new GetMethod(queryUrl);
            if (coneSession != null) {
                method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
            }
            ProxyHelper.executeMethod(client, method);
            logger.info("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)) {
                            GetMethod detailMethod = new GetMethod(
                                    id + "?format=rdf&eSciDocUserHandle=" + "TODO");

                            ProxyHelper.setProxy(client, detailsUrl.replace("$1", id));
                            client.executeMethod(detailMethod);
                            logger.info("CoNE query: " + id + "?format=rdf&eSciDocUserHandle=" + "TODO"
                                    + " 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.");
        return null;
        //throw new RuntimeException(e);
    }
}