Example usage for java.util TreeSet size

List of usage examples for java.util TreeSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

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

/**
 * Retrieves all available GridFTP servers from MDS.
 * /* w ww . ja  v  a 2  s . c  o m*/
 * @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.//from   w ww  .ja  v a2 s  .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.apache.hadoop.hbase.regionserver.HLog.java

private byte[][] cleanOldLogs() throws IOException {
    Long oldestOutstandingSeqNum = getOldestOutstandingSeqNum();
    // Get the set of all log files whose final ID is older than or
    // equal to the oldest pending region operation
    TreeSet<Long> sequenceNumbers = new TreeSet<Long>(
            this.outputfiles.headMap((Long.valueOf(oldestOutstandingSeqNum.longValue() + 1L))).keySet());
    // Now remove old log files (if any)
    int logsToRemove = sequenceNumbers.size();
    if (logsToRemove > 0) {
        if (LOG.isDebugEnabled()) {
            // Find associated region; helps debugging.
            byte[] oldestRegion = getOldestRegion(oldestOutstandingSeqNum);
            LOG.debug("Found " + logsToRemove + " hlogs to remove " + " out of total " + this.outputfiles.size()
                    + "; " + "oldest outstanding seqnum is " + oldestOutstandingSeqNum + " from region "
                    + Bytes.toString(oldestRegion));
        }/*  w w  w . j a  v  a  2  s  .  c  o m*/
        for (Long seq : sequenceNumbers) {
            deleteLogFile(this.outputfiles.remove(seq), seq);
        }
    }

    // If too many log files, figure which regions we need to flush.
    byte[][] regions = null;
    int logCount = this.outputfiles.size() - logsToRemove;
    if (logCount > this.maxLogs && this.outputfiles != null && this.outputfiles.size() > 0) {
        regions = findMemstoresWithEditsOlderThan(this.outputfiles.firstKey(), this.lastSeqWritten);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < regions.length; i++) {
            if (i > 0)
                sb.append(", ");
            sb.append(Bytes.toStringBinary(regions[i]));
        }
        LOG.info("Too many hlogs: logs=" + logCount + ", maxlogs=" + this.maxLogs + "; forcing flush of "
                + regions.length + " regions(s): " + sb.toString());
    }
    return regions;
}

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

public String[] getSubClusterWithMemAndCPUsFromClusterFromSite(String site, String cluster, String cpus,
        String mem) {// w  ww.j a  va2  s  .  c  om

    /*
     * [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:edu.internet2.middleware.subject.provider.LdapSourceAdapter.java

/**
 * {@inheritDoc}/*w  w w  .  j av a  2 s . c om*/
 */
@Override
public Set search(String searchValue) {
    Comparator cp = new LdapComparator();
    TreeSet result = new TreeSet(cp);
    Search search = getSearch("search");
    if (search == null) {
        log.error("searchType: \"search\" not defined.");
        return result;
    }
    Search searchA = getSearch("searchAttributes");
    boolean noAttrSearch = true;
    if (searchA != null)
        noAttrSearch = false;

    Iterator<SearchResult> ldapResults = getLdapResults(search, searchValue, allAttributeNames);
    if (ldapResults == null) {
        return result;
    }
    while (ldapResults.hasNext()) {
        SearchResult si = (SearchResult) ldapResults.next();
        Attributes attributes = si.getAttributes();
        Subject subject = createSubject(attributes);
        if (noAttrSearch)
            ((LdapSubject) subject).setAttributesGotten(true);
        result.add(subject);
    }

    log.debug("set has " + result.size() + " subjects");
    if (result.size() > 0)
        log.debug("first is " + ((Subject) result.first()).getName());
    return result;
}

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.
 * //from   ww w . j a va2s .c  o  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.
 * //from   ww w  . ja  v  a 2  s .  co m
 * @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.
 * /*from   w w  w .j  ava 2  s  . 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.
 * /*w w  w.  j  av a 2  s . c o  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.apache.roller.weblogger.ui.struts2.editor.Bookmarks.java

/**
 * Present the bookmarks and subfolders available in the folder specified
 * by the request./*from   www  .j  a  v  a  2  s  .  c  om*/
 */
public String execute() {

    // build list of folders for display
    TreeSet allFolders = new TreeSet(new FolderPathComparator());

    try {
        // Build list of all folders, except for current one, sorted by path.
        BookmarkManager bmgr = WebloggerFactory.getWeblogger().getBookmarkManager();
        List<WeblogBookmarkFolder> folders = bmgr.getAllFolders(getActionWeblog());
        for (WeblogBookmarkFolder fd : folders) {
            if (!fd.getId().equals(getFolderId())) {
                allFolders.add(fd);
            }
        }

        // build folder path
        WeblogBookmarkFolder parent = getFolder().getParent();
        if (parent != null) {
            List folderPath = new LinkedList();
            folderPath.add(0, getFolder());
            while (parent != null) {
                folderPath.add(0, parent);
                parent = parent.getParent();
            }
            setFolderPath(folderPath);
        }
    } catch (WebloggerException ex) {
        log.error("Error building folders list", ex);
        // TODO: i18n
        addError("Error building folders list");
    }

    if (allFolders.size() > 0) {
        setAllFolders(allFolders);
    }

    return LIST;
}