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.auscope.gridtools.RegistryQueryClient.java

/**
 * Retrieves all available GridFTP servers from MDS.
 * /*  w w w .  ja v  a  2s  .  com*/
 * @return Array of GridFTP server hostnames
 */
public String[] getAllGridFtpServers() {
    /*
     * //*[local-name()='Site']/child::node()[local-name()='StorageElement']
     * /child::node()[local-name()='AccessProtocol']
     * /child::node()[local-name()='Type'][text()='gsiftp']/parent::node()
     * /child::node()[local-name()='Endpoint']
     */

    String[] serverNames = new String[0];

    String xpathQuery = "//*[local-name()='Site']" + "/child::node()[local-name()='StorageElement']"
            + "/child::node()[local-name()='AccessProtocol']" + "/child::node()[local-name()='Type']"
            + "[text()='gsiftp']/parent::node()";

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

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

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

    return serverNames;
}

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

/**
 * Gets the storage element available at a site given the queue which will
 * be used./*  www . j a  va 2s.  c o m*/
 * 
 * <b>TODO: Not implemented properly yet...</b>
 * 
 * @param queue The queue to check
 * @return The available storage element
 */
public String getStorageElementFromComputingElement(String queue) {
    /*
     * //*[local-name()='Site']/child::node()[local-name()='Cluster']
     * /child::node()[local-name()='ComputingElement']
     * /child::node()[local-name()='Name'][text()='queueName']/parent::node()
     * /child::node()[local-name()='DefaultSE']
     */

    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Cluster']"
            + "/child::node()[local-name()='ComputingElement']"
            + "/child::node()[local-name()='Name'][text()='queueName']" + "/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, "DefaultSE"));
        }

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

    if (names.length == 0)
        return "";
    else
        return names[0];
}

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

public String[] getSubClusterWithMemAndCPUsFromClusterFromSite(String site, String cluster, String cpus,
        String mem) {/*from w ww. j  a  va2s  .  co  m*/

    /*
     * [local-name()='Site']/child::node()[local-name()='Name'][text()='iVEC']/parent::node()
     * /child::node()[local-name()='Cluster']/child::node()[local-name()='SubCluster']
     * /child::node()[local-name()='PhysicalCPUs'][number(text())>'16']/parent::node()
     * /child::node()[local-name()='MainMemory'][number(@RAMSize)>'5000']/parent::node()
     * /child::node()[local-name()='Name']
     */

    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Name'][text()='" + site + "']/"
            + "parent::node()/child::node()[local-name()='Cluster']/"
            + "child::node()[local-name()='SubCluster']";

    if (cpus.length() > 0) {
        xpathQuery += "/child::node()[local-name()='PhysicalCPUs'][number(text())>='" + cpus
                + "']/parent::node()";
    }
    if (mem.length() > 0) {
        xpathQuery += "/child::node()[local-name()='MainMemory'][number(@RAMSize)>='" + mem
                + "']/parent::node()";
    }

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

    String names[] = new String[0];

    // 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 subcluster that matches the code, version, number of CPUs, and
 * memory. CPUs, mem and version can be empty strings.
 * /*w  ww .ja va 2s .co  m*/
 * @param code    The code to find
 * @param version The version of the code
 * @param cpus    The number of CPUs to request
 * @param mem     The amount of memory to request
 * @return Name of the subcluster(s) that match
 */
public String[] getSubClusterWithSoftwareAndVersionWithMemAndCPUs(String code, String version, String cpus,
        String mem) {

    /*
     * //*[local-name()='Site']/child::node()[local-name()='Name'][text()='iVEC']/parent::node()
     * //*[local-name()='Site']/
     * /child::node()[local-name()='Cluster']/child::node()[local-name()='SubCluster']
     * /child::node()[local-name()='PhysicalCPUs'][number(text())>'16']/parent::node()
     * /child::node()[local-name()='MainMemory'][number(@RAMSize)>'5000']/parent::node()
     * /child::node()[local-name()='SoftwarePackage']
     * /child::node()[contains(name(), Name)][text()='MrBayes']
     * /parent::node()/child::node()[contains(name(),Version)][text()='3.1.2']
     * /ancestor::node()[local-name()='SubCluster']
     */

    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Cluster']/"
            + "child::node()[local-name()='SubCluster']";
    if (cpus.length() > 0) {
        xpathQuery += "/child::node()[local-name()='PhysicalCPUs'][number(text())>='" + cpus
                + "']/parent::node()";
    }
    if (mem.length() > 0) {
        xpathQuery += "/child::node()[local-name()='MainMemory'][number(@RAMSize)>='" + mem
                + "']/parent::node()";
    }

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

    if (version.length() > 0) {
        xpathQuery += "/child::node()[contains(name(),Version)][text()='" + version + "']/";
    }

    xpathQuery += "/ancestor::node()[local-name()='SubCluster']";

    String names[] = new String[0];

    // 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

/**
 * Retrieves all codes (software packages) available on the Grid.
 * //  w  w w . ja  v  a 2s.c  om
 * @return String[] Names of all codes available
 */
public String[] getAllCodesOnGrid() {
    String names[] = new String[0];
    String xpathQuery = "//*[local-name()='SoftwarePackage']";

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

    if (codeAvailNodeList != null) {
        // Keep codes unique using TreeSet
        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"));
        }

        // Shove in array
        names = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return names;
}

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

/**
 * Retrieves the names of all sites on the Grid.
 * /*  w  w w  .  j a v a2s  .  co  m*/
 * @return Array of site names
 */
public String[] getAllSitesOnGrid() {
    String[] hosts = new String[0];
    String xpathQuery = "//*[local-name()='Site']";
    // OldQuery: "/child::node()[local-name()='Name']"

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

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

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

        // Shove it into a String[] array
        hosts = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return hosts;
}

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

/**
 * Gets the names of the queues (computational elements) at a site.
 * //from   w w  w .  j a va  2  s  .  co m
 * @param site Name of the site 
 * @return An array of available queues
 */
public String[] getQueueNamesAtSite(String site) {
    String[] queueNames = new String[0];
    String xpathQuery = "//*[local-name()='Site']" + "/child::node()[local-name()='Name'][text()='" + site
            + "']" + "/ancestor::node()[local-name()='Site']"
            + "/descendant::node()[local-name()='ComputingElement']";

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

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

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

        // Shove in array
        queueNames = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return queueNames;
}

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

/**
 * Gets all GridFTP servers available on the Grid.
 * /*from w ww  . ja  va2 s.  c  o m*/
 * @return Array of hostnames of available GridFTP servers.
 */
public String[] getAllGridFTPServersOnGrid() {
    String[] serverNames = new String[0];

    String xpathQuery = "//*[local-name()='Site']" + "/child::node()[local-name()='StorageElement']"
            + "/child::node()[local-name()='AccessProtocol']" + "/child::node()[local-name()='Type']"
            + "[text()='gsiftp']/parent::node()";

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

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

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

        // Shove in array
        serverNames = myTreeSet.toArray(new String[myTreeSet.size()]);
    }

    return serverNames;
}

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

/**
 * Gets the storage path that satisfies the amount of disk space available
 * at a storage element./*from w  w  w  .  j  a v  a  2s  . co  m*/
 * 
 * <b>TODO: Not implemented properly yet...</b>
 * 
 * @param defaultSE The storage element to check
 * @param diskSpace The amount of diskspace required
 * @return The storage path that satisfies these requirements
 */
public String getStoragePathWithSpaceAvailFromDefaultStorageElement(String defaultSE, String diskSpace) {
    /*
     * //*[local-name()='Site']/child::node()[local-name()='StorageElement']
     * [@UniqueID='defaultSE']/child::node()[local-name()='StorageArea']
     * /child::node()[local-name()='AvailableSpace'][number(text())>diskSpace]/parent::node()
     * /child::node()[local-name()='Path']
     */

    String storagePath = "";

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

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

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

        for (int i = 0; i < pathNodeList.getLength(); i++) {
            Element siteEl = (Element) pathNodeList.item(i);
            myTreeSet.add(getTextValue(siteEl, "DefaultSE"));
        }
        // TODO: THIS IS WRONG.
        storagePath = myTreeSet.toArray(new String[myTreeSet.size()])[0];
    }

    return storagePath;
}

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

/**
 * Gets the email address of a site's support contact
 * /*from w  ww  .  ja  v a2 s  . c o m*/
 * @param site The site to check
 * @return The singular site email address string
 */
public String getSiteContactEmailAtSite(String site) {
    String xpathQuery = "//*[local-name()='Site']/child::node()[local-name()='Name']"
            + "[translate(text(),'abcdefghijklmnopqrstuvwxyz'," + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ')=translate('"
            + site + "'," + "'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')]" + "/parent::node()";

    String email = "";

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

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

        // Take the first element.... pretty poor way to do it...
        email = myTreeSet.toArray(new String[myTreeSet.size()])[0];
    }

    return email;
}