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:com.zimbra.common.util.ngxlookup.ZimbraNginxLookUpClient.java

/**
 * Parse a server list./*w  ww  .  ja  va 2 s .com*/
 * Each server value is hostname:port or just hostname.
 * @param serverList
 * @return
 */
private List<Route> parseServerList(String[] servers, int defaultPort) {
    // Eliminate duplicates and sort case-insensitively.  This negates operator error
    // configuring server list with inconsistent order on different Nginx Route Handler clients.
    // TreeSet provides deduping and sorting.
    TreeSet<String> tset = new TreeSet<String>();
    for (int i = 0; i < servers.length; ++i) {
        tset.add(servers[i].toLowerCase());
    }
    servers = tset.toArray(new String[0]);
    if (servers != null) {
        List<Route> addrs = new ArrayList<Route>(servers.length);
        for (String server : servers) {
            if (server.length() == 0)
                continue;
            // In case of nginx lookup handlers, there might be additional '/service/extension/nginx-lookup' at the end.
            // Remove it as the parser expects a server value with hostname:port or just hostname
            if (defaultPort == DEFAULT_NGINX_HANDLER_PORT) {
                server = server.replace(urlExtension, "");
                ZimbraLog.misc.debug("Lookup server after removing urlExtension " + server);
            }
            ZimbraLog.misc.debug("Server before parsing " + server);
            String[] parts = server.split(":");
            if (parts != null) {
                String host;
                int port = defaultPort;
                if (parts.length == 1) {
                    host = parts[0];
                } else if (parts.length == 2) {
                    host = parts[0];
                    try {
                        port = Integer.parseInt(parts[1]);
                    } catch (NumberFormatException e) {
                        ZimbraLog.misc.warn("Invalid server parsing ports " + server);
                        continue;
                    }
                } else {
                    ZimbraLog.misc.warn("Invalid server " + server + "has %d parts" + parts.length);
                    continue;
                }
                Route rt = this.new Route(new InetSocketAddress(host, port), 0);
                addrs.add(rt);
            } else {
                ZimbraLog.misc.warn("Invalid server has null parts" + server);
                continue;
            }
        }
        return addrs;
    } else {
        return new ArrayList<Route>(0);
    }
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.FifoIntraQueuePreemptionPlugin.java

public void validateOutSameAppPriorityFromDemand(Resource cluster,
        TreeSet<TempAppPerPartition> appsOrderedfromLowerPriority) {

    TempAppPerPartition[] apps = appsOrderedfromLowerPriority
            .toArray(new TempAppPerPartition[appsOrderedfromLowerPriority.size()]);
    if (apps.length <= 0) {
        return;//from   w ww .j av a  2  s .c om
    }

    int lPriority = 0;
    int hPriority = apps.length - 1;

    while (lPriority < hPriority && !apps[lPriority].equals(apps[hPriority])
            && apps[lPriority].getPriority() < apps[hPriority].getPriority()) {
        Resource toPreemptFromOther = apps[hPriority].getToBePreemptFromOther();
        Resource actuallyToPreempt = apps[lPriority].getActuallyToBePreempted();
        Resource delta = Resources.subtract(apps[lPriority].toBePreempted, actuallyToPreempt);

        if (Resources.greaterThan(rc, cluster, delta, Resources.none())) {
            Resource toPreempt = Resources.min(rc, cluster, toPreemptFromOther, delta);

            apps[hPriority].setToBePreemptFromOther(Resources.subtract(toPreemptFromOther, toPreempt));
            apps[lPriority].setActuallyToBePreempted(Resources.add(actuallyToPreempt, toPreempt));
        }

        if (Resources.lessThanOrEqual(rc, cluster, apps[lPriority].toBePreempted,
                apps[lPriority].getActuallyToBePreempted())) {
            lPriority++;
            continue;
        }

        if (Resources.equals(apps[hPriority].getToBePreemptFromOther(), Resources.none())) {
            hPriority--;
            continue;
        }
    }
}

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

static public String[] listApis(@Nonnull String provider, @Nonnull String cloud) {
    provider = provider.replaceAll(DELIMITER_REGEX, "_");
    cloud = cloud.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 > 3 && parts[0].equals(provider) && parts[1].equals(cloud)) {
                if (parts.length == 4) {
                    list.add(parts[3]);//from  w  ww . jav a2 s.c o m
                } else {
                    StringBuilder tmp = new StringBuilder();

                    for (int i = 3; i < parts.length; i++) {
                        tmp.append(parts[i]);
                        if (i < parts.length - 1) {
                            tmp.append(DELIMITER);
                        }
                    }
                    list.add(tmp.toString());
                }
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

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

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

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

            if (parts.length > 3 && parts[0].equals(provider) && parts[1].equals(cloud)) {
                if (parts.length == 4) {
                    list.add(parts[3]);/*  w w w .  j  a  va  2s  .c o m*/
                } else {
                    StringBuilder tmp = new StringBuilder();

                    for (int i = 3; i < parts.length; i++) {
                        tmp.append(parts[i]);
                        if (i < parts.length - 1) {
                            tmp.append(DELIMITER);
                        }
                    }
                    list.add(tmp.toString());
                }
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:org.wso2.andes.kernel.slot.SlotManagerStandalone.java

/**
 * {@inheritDoc}/*from www.ja  v  a 2s . c o  m*/
 */
@Override
public long getSafeZoneLowerBoundId(String queueName) throws AndesException {
    long lowerBoundId = -1;
    String lockKey = queueName + SlotManagerStandalone.class;
    synchronized (lockKey.intern()) {
        TreeSet<Long> messageIDSet = slotIDMap.get(queueName);
        //set the lower bound Id for safety delete region as the safety slot count interval upper bound id + 1
        if (messageIDSet.size() >= safetySlotCount) {
            lowerBoundId = messageIDSet.toArray(new Long[messageIDSet.size()])[safetySlotCount - 1] + 1;
            // Inform the slot manager regarding the current expiry deletion range and queue.
            setDeletionTaskState(queueName, lowerBoundId);
        }
    }
    return lowerBoundId;
}

From source file:org.egov.works.master.service.ContractorService.java

public String[] getContractorMasterMandatoryFields() {
    final TreeSet<String> set = new TreeSet<>(Arrays.asList(getcontractorMasterSetMandatoryFields()));
    set.removeAll(Arrays.asList(getcontractorMasterSetHiddenFields()));
    return set.toArray(new String[set.size()]);
}

From source file:com.yahoo.ycsb.bulk.hbase.RangePartitioner.java

private synchronized Text[] getCutPoints() throws IOException {
    if (cutPointArray == null) {
        String cutFileName = conf.get(CUTFILE_KEY);
        Path[] cf = DistributedCache.getLocalCacheFiles(conf);

        if (cf != null) {
            for (Path path : cf) {
                if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) {
                    TreeSet<Text> cutPoints = new TreeSet<Text>();
                    Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString())));
                    try {
                        while (in.hasNextLine())
                            cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes())));
                    } finally {
                        in.close();/*from  w ww.j a  va 2  s  .c om*/
                    }
                    cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]);
                    break;
                }
            }
        }
        if (cutPointArray == null)
            throw new FileNotFoundException(cutFileName + " not found in distributed cache");
    }
    return cutPointArray;
}

From source file:tvbrowser.ui.settings.looksSettings.SkinLNFSettings.java

private String[] getThemePacks() {
    final TreeSet<String> themepacks = new TreeSet<String>();
    themepacks.addAll(Arrays.asList(getThemePacks(new File("themepacks"))));
    themepacks.addAll(Arrays.asList(getThemePacks(new File(Settings.getUserDirectoryName(), "themepacks"))));

    if (OperatingSystem.isMacOs()) {
        themepacks.addAll(//w  w  w .ja va2  s.c  om
                Arrays.asList(getThemePacks(new File(Settings.getOSLibraryDirectoryName() + "themepacks"))));
    }

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

From source file:org.mrgeo.data.accumulo.partitioners.AccumuloMrGeoRangePartitioner.java

private synchronized TileIdWritable[] getCutPoints() throws IOException {
    if (cutPointArray == null) {
        String cutFileName = conf.get(CUTFILE_KEY);
        Path[] cf = DistributedCache.getLocalCacheFiles(conf);

        if (cf != null) {
            for (Path path : cf) {
                if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) {
                    TreeSet<Text> cutPoints = new TreeSet<Text>();
                    Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString())));
                    try {
                        while (in.hasNextLine())
                            cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes())));
                    } finally {
                        in.close();//  w w  w  .j  a v  a2  s .com
                    }
                    cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]);
                    break;
                }
            }
        }
        if (cutPointArray == null)
            throw new FileNotFoundException(cutFileName + " not found in distributed cache");
    }
    tileIdPointArray = new TileIdWritable[cutPointArray.length];
    for (int x = 0; x < cutPointArray.length; x++) {
        byte[] b = cutPointArray[x].getBytes();
        ByteBuffer buffer = ByteBuffer.wrap(b);
        long k = buffer.getLong();
        tileIdPointArray[x] = new TileIdWritable(k);
    }

    return tileIdPointArray;
}

From source file:com.addthis.hydra.data.query.QueryElementNode.java

public QueryElementNode parse(String tok, MutableInt nextColumn) {
    if (tok.equals("+..")) {
        up = true;/*from w  w w . ja  v  a2 s .  c o  m*/
        column = Integer.toString(nextColumn.intValue());
        nextColumn.increment();
        return this;
    }
    if (tok.equals("..")) {
        up = true;
        return this;
    }
    List<String> matchList = new ArrayList<>(3);
    List<String> trapList = new ArrayList<>(3);
    if (tok.indexOf(';') > 0) {
        tok = tok.replace(';', ',');
        flat = true;
    }
    if (tok.startsWith("!")) {
        not = true;
        regex = true;
        tok = tok.substring(1);
    }
    if (tok.startsWith("|")) {
        tok = tok.substring(1);
        regex = true;
    }
    tok = extractDefaultValue(tok);

    QueryElementNode.MODE mode = MODE.MATCH;

    String[] list = LessStrings.splitArray(tok, ",");
    for (String component : list) {
        if (component.startsWith("*")) {
            component = component.substring(1);
            mode = MODE.MATCH;
        } else if (component.startsWith("+")) {
            component = component.substring(1);
            if (component.startsWith("+")) {
                component = component.substring(1);
                range = true;
            }
            if (component.startsWith("@")) {
                component = component.substring(1);
                rangeStrict = true;
            }
            mode = MODE.MATCH;
            int close;
            if (component.startsWith("{") && (close = component.indexOf("}")) > 0) {
                column = component.substring(1, close);
                component = component.substring(close + 1);
            } else {
                column = Integer.toString(nextColumn.intValue());
                nextColumn.increment();
            }
        } else if (component.startsWith("-")) {
            component = component.substring(1);
            mode = MODE.TRAP;
        }
        if (component.startsWith("%?")) {
            data = memKey;
            regex = true;
            continue;
        }
        if (component.startsWith("%") && !(component.startsWith("%2d") || component.startsWith("%2c"))) {
            String[] kv = LessBytes.urldecode(component.substring(1)).split("=", 2);
            if (kv.length == 2) {
                data = kv[0];
                dataKey = kv[1];
            } else if (kv.length == 1) {
                data = kv[0];
            }
            continue;
        }
        if (component.startsWith("@@")) {
            path = LessStrings.splitArray(LessBytes.urldecode(component.substring(2)), "/");
            continue;
        } else if (component.startsWith("@")) {
            component = component.substring(1);
            mode = MODE.MATCH;
            rangeStrict = true;
        }
        component = LessBytes.urldecode(component);
        if (component.length() > 0) {
            if (mode != MODE.TRAP) {
                matchList.add(component);
            } else {
                trapList.add(component);
            }
        }
    }
    if (matchList.size() > 0) {
        String[] out = new String[matchList.size()];
        match = matchList.toArray(out);
        if (tok.startsWith(",")) {
            TreeSet<String> sorted = new TreeSet<>();
            sorted.addAll(matchList);
            match = sorted.toArray(out);
        }
    }
    if (trapList.size() > 0) {
        trap = trapList.toArray(new String[trapList.size()]);
    }
    return this;
}