Example usage for java.util TreeSet toArray

List of usage examples for java.util TreeSet toArray

Introduction

In this page you can find the example usage for java.util TreeSet toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:org.lockss.devtools.CrawlRuleTester.java

private void checkRules() {
    outputMessage("\nChecking " + m_baseUrl, TEST_SUMMARY_MESSAGE);
    outputMessage("crawl depth: " + m_crawlDepth + "     crawl delay: " + m_crawlDelay + " ms.", PLAIN_MESSAGE);

    TreeSet crawlList = new TreeSet();
    TreeSet fetched = new TreeSet();
    // inialize with the baseUrl
    crawlList.add(m_baseUrl);/*from  www  .ja  va2 s .c om*/
    depth_incl = new int[m_crawlDepth];
    depth_fetched = new int[m_crawlDepth];
    depth_parsed = new int[m_crawlDepth];
    long start_time = TimeBase.nowMs();
    for (int depth = 1; depth <= m_crawlDepth; depth++) {
        if (isInterrupted()) {
            return;
        }
        m_curDepth = depth;
        if (crawlList.isEmpty() && depth <= m_crawlDepth) {
            outputMessage("\nNothing left to crawl, exiting after depth " + (depth - 1), PLAIN_MESSAGE);
            break;
        }
        String[] urls = (String[]) crawlList.toArray(new String[0]);
        crawlList.clear();
        outputMessage("\nDepth " + depth, PLAIN_MESSAGE);
        for (int ix = 0; ix < urls.length; ix++) {
            if (isInterrupted()) {
                return;
            }
            pauseBeforeFetch();
            String urlstr = urls[ix];

            m_incls.clear();
            m_excls.clear();

            // crawl the page
            buildUrlSets(urlstr);
            fetched.add(urlstr);
            // output incl/excl results,
            // add the new_incls to the crawlList for next crawl depth loop
            crawlList.addAll(outputUrlResults(urlstr, m_incls, m_excls));
        }
    }
    long elapsed_time = TimeBase.nowMs() - start_time;
    outputSummary(m_baseUrl, fetched, crawlList, elapsed_time);
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets the names of the subclusters at a site.
 * /* w  w  w  .  j a v a  2s  . c o m*/
 * @param site The site to check
 * @return An array of subcluster names
 */
public String[] getSubClusterNamesAtSite(String site) {
    String names[] = new String[0];
    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Name']"
            + "[translate(text(),'abcdefghijklmnopqrstuvwxyz'," + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('"
            + site + "'," + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')]"
            + "/parent::node()/descendant::node()[local-name()='Cluster']";

    // Parse the document
    NodeList clusterNodeList = turboMDSquery(xpathQuery);

    if (clusterNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < clusterNodeList.getLength(); i++) {
            Element siteEl = (Element) clusterNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets the clusters available at a site.
 * //  ww  w  .ja v a2 s . co  m
 * @param site The name of the site
 * @return An array of the available clusters.
 */
public String[] getClusterNamesAtSite(String site) {
    String clusters[] = new String[0];
    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Name']"
            + "[translate(text(),'abcdefghijklmnopqrstuvwxyz'," + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('"
            + site + "'," + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')]"
            + "/parent::node()/descendant::node()[local-name()='Cluster']";

    // Query MDS file.
    NodeList codeAvailNodeList = turboMDSquery(xpathQuery);

    if (codeAvailNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < codeAvailNodeList.getLength(); i++) {
            Element siteEl = (Element) codeAvailNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        clusters = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return clusters;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets a list of all the sites that have the specified version of a code.
 * //from w w w .  ja va  2s .  c o  m
 * @param code The name of the code
 * @param version The particular version required
 * @return An array of sites with this exact code/version combination
 */
public String[] getAllSitesWithAVersionOfACode(String code, String version) {
    String names[] = new String[0];
    String versionString = "";
    if (version.length() > 0) {
        versionString = "/child::node()[contains(name(),Version)][text()='" + version + "']";
    }

    String xpathQuery = "//*[local-name()='SoftwarePackage']/child::node()[contains(name(),Name)]" + "[text()='"
            + code + "']/parent::node()" + versionString + "/ancestor::node()[local-name()='Site']";

    // Parse the document
    NodeList codeAvailNodeList = turboMDSquery(xpathQuery);

    if (codeAvailNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < codeAvailNodeList.getLength(); i++) {
            Element siteEl = (Element) codeAvailNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets all the distinct versions of a particular code that are available
 * on the Grid. This method must query all the sites for their versions of
 * this code, and then collate the information into a list of unique
 * versions./*from  w  w  w.  ja  v a  2  s  .  c om*/
 * 
 * @return An array of all versions available
 */
public String[] getAllVersionsOfCodeOnGrid(String code) {
    String versions[] = new String[0];
    String xpathQuery = "//*[local-name()='SoftwarePackage']" + "/ancestor::node()[local-name()='Site']"
            + "/descendant::node()[local-name()='SoftwarePackage']"
            + "/child::node()[contains(name(),Name)][text()='" + code + "']" + "/parent::node()";

    // Query MDS file
    NodeList verAvailableList = turboMDSquery(xpathQuery);

    if (verAvailableList != null) {
        // Keep unique using TreeSet
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < verAvailableList.getLength(); i++) {
            Element siteEl = (Element) verAvailableList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Version"));
        }

        versions = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return versions;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets the compute elements in a particular cluster at the given site.
 * /*from  w ww .j  a  v a2 s . c om*/
 * @param site The site to query
 * @param cluster The cluster at the site to query
 * @return An array of the available compute elements
 */
public String[] getComputeElementsOfClusterAtSite(String site, String cluster) {
    String names[] = new String[0];
    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Name']"
            + "[translate(text(),'abcdefghijklmnopqrstuvwxyz'," + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('"
            + site + "'," + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')]"
            + "/parent::node()/descendant::node()[local-name()='Cluster']"
            + "/child::node()[local-name()='Name'][translate(text(),"
            + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" + "=translate('" + cluster
            + "','abcdefghijklmnopqrstuvwxyz'" + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ')]/parent::node()"
            + "/descendant::node()[local-name()='ComputingElement']";

    // Parse the document
    NodeList computeElsNodeList = turboMDSquery(xpathQuery);

    if (computeElsNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < computeElsNodeList.getLength(); i++) {
            Element siteEl = (Element) computeElsNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets a list of versions of a code available at a site.
 * /*from w  w  w  .j a va  2  s. co m*/
 * @param site The name of the site     
 * @param code The name of the code
 * @return An array of versions of this code
 */
public String[] getVersionsOfCodeAtSite(String site, String code) {
    String[] version = new String[0];
    String xpathQuery = "//*[local-name()='Site']" + "/child::node()[local-name()='Name'][text()='" + site
            + "']" + "/ancestor::node()[local-name()='Site']"
            + "/descendant::node()[local-name()='SoftwarePackage']" + "/child::node()[local-name()='Name']"
            + "[text()='" + code + "']/parent::node()";

    // Parse the document
    NodeList codeVersionNodeList = turboMDSquery(xpathQuery);

    if (codeVersionNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();
        for (int i = 0; i < codeVersionNodeList.getLength(); i++) {
            Element siteEl = (Element) codeVersionNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Version"));
        }

        version = myTreeSet.toArray(new String[myTreeSet.size()]);
    }
    return version;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets the free job slots of compute elements of a cluster at a site.
 * /*ww w  .  j  av a 2s . co m*/
 * @param site      The site name
 * @param cluster   The cluster name
 * @param computeEl The compute element
 * @return The free job slots
 */
public String[] getFreeJobSlotsOfComputeElementsOfClusterAtSite(String site, String cluster, String computeEl) {

    String names[] = new String[0];
    String xpathQuery = "//*[local-name()='Site']" + "/child::node()[local-name()='Name']"
            + "[translate(text(),'abcdefghijklmnopqrstuvwxyz'," + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('"
            + site + "','abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')]"
            + "/parent::node()/descendant::node()[local-name()='Cluster']"
            + "/child::node()[local-name()='Name'][translate(text(),"
            + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" + "=translate('" + cluster
            + "','abcdefghijklmnopqrstuvwxyz'" + ",'ABCDEFGHIJKLMNOPQRSTUVWXYZ')]/parent::node()"
            + "/descendant::node()[local-name()='ComputingElement']";

    // Parse the document
    NodeList slotsAvailNodeList = turboMDSquery(xpathQuery);

    if (slotsAvailNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < slotsAvailNodeList.getLength(); i++) {
            Element siteEl = (Element) slotsAvailNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets all sites' code versions./*from w  ww.  jav a 2s.co  m*/
 * 
 * @param requestedCode the requested code
 * 
 * @return all sites' code versions
 */
public String[] getAllSitesCodeVersions(String requestedCode) {
    String versions[] = new String[0];
    String xpathQuery = "//*[local-name()='SoftwarePackage']" + "/ancestor::node()[local-name()='Site']"
            + "/descendant::node()[local-name()='SoftwarePackage']"
            + "/child::node()[contains(name(),Name)][text()='" + requestedCode + "']" + "/parent::node()";

    // Old Version.
    // "/child::node()[local-name()='Version']";

    // Parse the document
    NodeList codeAvailNodeList = turboMDSquery(xpathQuery);

    if (codeAvailNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < codeAvailNodeList.getLength(); i++) {
            Element siteEl = (Element) codeAvailNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Version"));
        }

        versions = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return versions;
}

From source file:org.auscope.gridtools.RegistryQueryClient.java

/**
 * Gets the queue (a.k.a. Compute Elements) that matches the walltime 
 * requested and the subcluster's hostname.
 * /*from   w w  w  . j ava  2  s .com*/
 * @param subCluster The subcluster's host name
 * @param wallTime   The walltime to request
 * @return A list of matching queues/computing elements
 */
public String[] getComputingElementForWalltimeAndSubcluster(String subCluster, String wallTime) {

    /*
     * //*[local-name()='Site']/child::node()[local-name()='Cluster']
     * /child::node()[local-name()='ComputingElement']
     * /child::node()[local-name()='MaxWallClockTime'][number(text())>'16']/parent::node()
     * /child::node()[local-name()='HostName'][text()='hydra.sapac.edu.au']/parent::node()
     */

    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Cluster']"
            + "/child::node()[local-name()='ComputingElement']"
            + "/child::node()[local-name()='HostName'][text()='" + subCluster + "']/parent::node()";

    if (wallTime.length() > 0) {
        xpathQuery += "/child::node()[local-name()='MaxWallClockTime']" + "[number(text())>'" + wallTime
                + "']/parent::node()";
    }

    String names[] = new String[0];

    // Parse the document
    NodeList elementNodeList = turboMDSquery(xpathQuery);

    if (elementNodeList != null) {
        TreeSet<String> myTreeSet = new TreeSet<String>();

        for (int i = 0; i < elementNodeList.getLength(); i++) {
            Element siteEl = (Element) elementNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "Name"));
        }

        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}