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.onosproject.drivers.microsemi.yang.utils.CeVlanMapUtils.java

/**
 * Add an additional vlan id to an existing string representation.
 * @param existingMap An array of vlan ids
 * @param newVlan The new vlan ID to add
 * @return A string representation delimited by commas and colons
 *///  ww  w .jav a2s  .c  o  m
public static String addtoCeVlanMap(String existingMap, Short newVlan) {
    Short[] vlanArray = getVlanSet(existingMap);
    TreeSet<Short> vlanSet = new TreeSet<>();
    for (Short vlan : vlanArray) {
        vlanSet.add(vlan);
    }

    vlanSet.add(newVlan);

    return vlanListAsString(vlanSet.toArray(new Short[vlanSet.size()]));
}

From source file:org.onosproject.drivers.microsemi.yang.utils.CeVlanMapUtils.java

/**
 * Remove a vlan id from an existing string representation.
 * @param existingMap An array of vlan ids
 * @param vlanRemove The vlan ID to remove
 * @return A string representation delimited by commas and colons
 *///from w  ww  .j av a2 s.c o m
public static String removeFromCeVlanMap(String existingMap, Short vlanRemove) {
    Short[] vlanArray = getVlanSet(existingMap);
    TreeSet<Short> vlanSet = new TreeSet<>();
    for (Short vlan : vlanArray) {
        if (vlan.shortValue() != vlanRemove.shortValue()) {
            vlanSet.add(vlan);
        }
    }

    return vlanListAsString(vlanSet.toArray(new Short[vlanSet.size()]));
}

From source file:com.espertech.esper.event.vaevent.PropertyUtility.java

private static MultiKey<String> getPropertiesContributed(EventType deltaEventType,
        String[] allPropertiesSorted) {

    TreeSet<String> props = new TreeSet<String>();
    for (String property : deltaEventType.getPropertyNames()) {
        for (String propInAll : allPropertiesSorted) {
            if (propInAll.equals(property)) {
                props.add(property);//w w w . j a  v a  2  s  .c om
                break;
            }
        }
    }
    return new MultiKey<String>(props.toArray(new String[props.size()]));
}

From source file:reconcile.hbase.mapreduce.KeyListInputFormat.java

public static String[] getLocations(HConnection connection, String tableName, List<String> keys)
        throws IOException {
    TreeSet<String> hosts = new TreeSet<String>();

    for (String key : keys) {
        HRegionLocation region = connection.getRegionLocation(tableName.getBytes(), key.getBytes(), true);
        String hostName = region.getServerAddress().getHostname();
        LOG.debug("Key(" + key + ") found on host (" + hostName + ")");
        hosts.add(hostName);//  w w w .  jav a  2  s .c  o  m
    }
    return hosts.toArray(new String[hosts.size()]);
}

From source file:org.yccheok.jstock.gui.OptionsNetworkJPanel.java

private static String[] getPriceSourceEntryValues(Country country) {
    Set<PriceSource> priceSources = org.yccheok.jstock.engine.Utils.getSupportedPriceSources(country);
    TreeSet<String> treeSet = new TreeSet<String>();
    for (PriceSource priceSource : priceSources) {
        treeSet.add(priceSource.name());
    }/*from ww  w . java2 s. c  om*/
    return treeSet.toArray(new String[treeSet.size()]);
}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

/**
 * @return Sorted Set of all player's nicknames who has ever conntected to
 *         the server. The nicknames are all in lowercase!
 *///from w  w  w  .  j a  v a 2  s  .  co m
public static String[] getAllPlayerNames() {

    TreeSet<String> playerNames = new TreeSet<String>();

    OfflinePlayer[] players = Bukkit.getServer().getOfflinePlayers();
    for (OfflinePlayer player : players)
        playerNames.add(player.getName().toLowerCase());

    return playerNames.toArray(new String[playerNames.size()]);
}

From source file:org.dasein.cloud.util.APITrace.java

static public String[] listProviders() {
    TreeSet<String> providers = new TreeSet<String>();

    synchronized (apiCount) {
        for (String call : apiCount.keySet()) {
            String[] parts = call.split(DELIMITER_REGEX);

            if (parts.length > 0) {
                providers.add(parts[0]);
            }/* ww  w . java2s . c om*/
        }
    }
    return providers.toArray(new String[providers.size()]);
}

From source file:org.dasein.cloud.util.APITrace.java

static public String[] listClouds(@Nonnull String provider) {
    provider = provider.replaceAll(DELIMITER_REGEX, "_");
    TreeSet<String> list = new TreeSet<String>();

    synchronized (apiCount) {
        for (String call : apiCount.keySet()) {
            String[] parts = call.split(DELIMITER_REGEX);

            if (parts.length > 1 && parts[0].equals(provider)) {
                list.add(parts[1]);/*  www.  ja v  a  2 s  . c  o  m*/
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:org.apache.hadoop.hbase.allocation.CheckMeta.java

/**
 * get table descriptors.//from ww w .  j  a  v a  2 s. c om
 * 
 * @return table descriptors.
 */
public static HTableDescriptor[] getTables() {
    HTableDescriptor[] ret = null;
    try {
        Scan s = new Scan();
        if (t == null)
            t = new HTable(".META.");
        t.setScannerCaching(1000);
        s.setCaching(1000);
        ResultScanner sn = t.getScanner(s);
        Result r = null;
        final TreeSet<HTableDescriptor> uniqueTables = new TreeSet<HTableDescriptor>();
        while ((r = sn.next()) != null) {
            byte[] value = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
            HRegionInfo info = null;
            if (value != null) {
                info = Writables.getHRegionInfo(value);
            }
            // Only examine the rows where the startKey is zero length
            if (info != null && info.getStartKey().length == 0) {
                uniqueTables.add(info.getTableDesc());
            }
        }
        try {
            sn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ret = uniqueTables.toArray(new HTableDescriptor[uniqueTables.size()]);
        return ret;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.lternet.pasta.portal.search.AuthorSearch.java

/**
 * Parses the Solr query results using regular expression matching (as
 * opposed to XML parsing)//w w w  .ja v a2s . c o  m
 * 
 * @param xml             the Solr query results, an XML document string
 * @param fieldName       the field name to parse out of the XML, e.g. "author"
 * @return                a String array of field values parsed from the XML
 */
private static String[] parseQueryResults(String xml, String fieldName) {
    String[] values = null;
    final String patternStr = String.format("^\\s*<%s>(.+)</%s>\\s*$", fieldName, fieldName);
    Pattern pattern = Pattern.compile(patternStr);
    TreeSet<String> valueSet = new TreeSet<String>();

    if (xml != null) {
        String[] lines = xml.split("\n");
        for (String line : lines) {
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                String capturedValue = matcher.group(1).trim();
                String unescapedXML = StringEscapeUtils.unescapeXml(capturedValue);
                String trimmedXML = unescapedXML.replace("\r", " ").replace("\n", " ").replaceAll("\\s+", " ")
                        .trim();
                String escapedXML = StringEscapeUtils.escapeXml(trimmedXML);
                valueSet.add(escapedXML);
            }
        }

        values = valueSet.toArray(new String[valueSet.size()]);
    }

    return values;
}