Example usage for java.util NavigableSet iterator

List of usage examples for java.util NavigableSet iterator

Introduction

In this page you can find the example usage for java.util NavigableSet iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set, in ascending order.

Usage

From source file:org.apache.hadoop.raid.RaidHistogram.java

public synchronized void filterStalePoints(long endTime) throws IOException {
    int last = windowNum - 1;
    long windowTime = windows.get(last);
    NavigableSet<Point> windowSet = points.headSet(new Point(0, "", endTime - windowTime, null));
    Iterator<Point> windowIterator = windowSet.iterator();
    while (windowIterator.hasNext()) {
        Point p = windowIterator.next();
        if (p.value == RECOVERY_FAIL) {
            AtomicInteger ca = failedRecoveredFiles.get(p.path);
            if (ca == null) {
                throw new IOException(p.path + " doesn't have counter in failedRecoveredFiles");
            }/*from w w  w.j  av  a2s.com*/
            if (ca.decrementAndGet() == 0) {
                totalFailedPaths.decrementAndGet(last);
                failedRecoveredFiles.remove(p.path);
            }
        } else {
            CounterArray ca = histo.get(p.value);
            if (ca == null) {
                throw new IOException(p.value + " doesn't have counter in histo");
            }
            if (ca.decrementAndGet(last) == 0) {
                histo.remove(p.value);
            }
            totalPoints.decrementAndGet(last);
        }
        points.remove(p);
    }
}

From source file:org.apache.hadoop.raid.RaidHistogram.java

public synchronized void collectCounters(long endTime) throws IOException {
    for (int i = 0; i < windowNum - 1; i++) {
        long windowTime = windows.get(i);
        // reset totalFailedPaths and totalPoints
        totalFailedPaths.get(i).set(0);/*from   w w  w .  ja va2 s . co m*/
        totalPoints.get(i).set(0);
        NavigableSet<Point> windowSet = points.tailSet(new Point(0, "", endTime - windowTime, null));
        Iterator<Point> windowIterator = windowSet.iterator();
        Set<String> failedRecoveredFiles = new HashSet<String>();
        while (windowIterator.hasNext()) {
            Point p = windowIterator.next();
            if (p.value == RECOVERY_FAIL) {
                if (failedRecoveredFiles.add(p.path)) {
                    totalFailedPaths.incrementAndGet(i);
                }
            } else {
                CounterArray ca = histo.get(p.value);
                if (ca == null) {
                    throw new IOException(p.value + " doesn't have counter in histo");
                }
                ca.incrementAndGet(i);
                totalPoints.incrementAndGet(i);
            }
        }
    }
}

From source file:com.ery.hadoop.mrddx.hbase.HbaseRecordReader.java

/**
 * ???/*from  w  ww . j a v a  2 s .  c  om*/
 * 
 * @param scan ??
 */
private void printScanConditions(Scan scan) {
    StringBuilder logMeg = new StringBuilder();
    logMeg.append("TimeRange==>");
    logMeg.append(scan.getTimeRange().getMin());
    logMeg.append(":");
    logMeg.append(scan.getTimeRange().getMax());
    logMeg.append("\n");
    logMeg.append("Filter==>");
    Filter filter = scan.getFilter();
    if (null != filter && filter instanceof FilterList) {
        List<Filter> filterLst = ((FilterList) filter).getFilters();
        for (Filter f : filterLst) {
            logMeg.append(f.getClass().getName());
            logMeg.append(":");
            logMeg.append(f.toString());
        }
    }
    logMeg.append("\n");
    logMeg.append("Family-Column==>");
    Map<byte[], NavigableSet<byte[]>> mapFamily = scan.getFamilyMap();
    Iterator<byte[]> iterator = mapFamily.keySet().iterator();
    while (iterator.hasNext()) {
        byte[] key = iterator.next();
        logMeg.append(new String(key));
        NavigableSet<byte[]> set = mapFamily.get(key);
        if (null == set) {
            continue;
        }
        Iterator<byte[]> setIterator = set.iterator();
        while (setIterator.hasNext()) {
            logMeg.append(new String(setIterator.next()));
            logMeg.append(",");
        }
    }
    logMeg.append("\n");
    logMeg.append("MaxVersions==>");
    logMeg.append(scan.getMaxVersions());
    logMeg.append("\n");
    logMeg.append("StartRow==>");
    logMeg.append(new String(scan.getStartRow()));
    logMeg.append("\n");
    logMeg.append("StopRow==>");
    logMeg.append(new String(scan.getStopRow()));
    MRLog.info(LOG, "[HBase scan conditions]\n" + logMeg.toString());
}

From source file:org.structnetalign.merge.BronKerboschMergeJob.java

@Override
public List<NavigableSet<Integer>> call() throws Exception {

    logger.info("Searching for cliques on job " + index + " containing " + graph.getVertexCount()
            + " vertices and " + graph.getHomologyCount() + " homology edges");

    // find the cliques
    BronKerboschCliqueFinder<Integer, HomologyEdge> finder = new BronKerboschCliqueFinder<>();

    // these cliques are ordered from largest to smallest
    Collection<Set<Integer>> cliques = finder.transform(graph.getHomology());

    // just report the cliques we're using
    logger.info("Job " + index + ": " + "Found " + cliques.size() + " maximal cliques");
    int i = 1;/*from w  w w  .ja va2  s. c om*/
    for (Set<Integer> clique : cliques) {
        logger.debug("Job " + index + ": " + "Clique " + i + ": " + clique);
        i++;
    }

    // partition the cliques by sets of interactions
    // we call these (maximal) degenerate sets
    List<NavigableSet<Integer>> simpleDegenerateSets = new ArrayList<NavigableSet<Integer>>();
    for (Set<Integer> clique : cliques) {
        NavigableMap<String, NavigableSet<Integer>> degenerateSetMap = new TreeMap<>();
        for (int v : clique) {
            Collection<Integer> neighbors = graph.getInteractionNeighbors(v);
            String hash = hashVertexInteractions(neighbors);
            NavigableSet<Integer> degenerateSet = degenerateSetMap.get(hash);
            if (degenerateSet == null) {
                degenerateSet = new TreeSet<>();
                degenerateSetMap.put(hash, degenerateSet);
            }
            degenerateSet.add(v);
            logger.trace("Job " + index + ": " + "Found " + hash + " --> " + degenerateSetMap.get(hash));
        }
        for (NavigableSet<Integer> set : degenerateSetMap.values()) {
            simpleDegenerateSets.add(set);
        }
    }

    /*
     * Now sort the degenerate sets from largest to smallest.
     * Take into account the edge case where the sizes are the same.
     */
    Comparator<NavigableSet<Integer>> comparator = new Comparator<NavigableSet<Integer>>() {
        @Override
        public int compare(NavigableSet<Integer> clique1, NavigableSet<Integer> clique2) {
            if (CollectionUtils.isEqualCollection(clique1, clique2))
                return 0;
            if (clique1.size() < clique2.size()) {
                return 1;
            } else if (clique1.size() > clique2.size()) {
                return -1;
            } else {
                Iterator<Integer> iter1 = clique1.iterator();
                Iterator<Integer> iter2 = clique2.iterator();
                while (iter1.hasNext()) { // we know they're the same size
                    int v1 = iter1.next();
                    int v2 = iter2.next();
                    if (v1 < v2) {
                        return 1;
                    } else if (v1 > v2) {
                        return -1;
                    }
                }
            }
            // they're the same throughout, so they're equal
            return 0;
        }
    };
    List<NavigableSet<Integer>> sortedDegenerateSets = new ArrayList<>(simpleDegenerateSets.size());
    sortedDegenerateSets.addAll(simpleDegenerateSets);
    Collections.sort(sortedDegenerateSets, comparator);

    /*
     * Now we want to return only the maximal maximal degenerate sets.
     */

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

    List<NavigableSet<Integer>> finalDegenerateSets = new ArrayList<>(sortedDegenerateSets.size());

    int nTrivial = 0;
    int nWeak = 0; // a degenerate set is weak if it contains a vertex that is added first

    forcliques: for (NavigableSet<Integer> set : sortedDegenerateSets) {

        // discard trivial degenerate sets
        if (set.size() < 2) {
            nTrivial++;
            continue;
        }

        // verify that we haven't already used any vertex in this degenerate set
        for (int v : set) {
            String hash = NetworkUtils.hash(v); // use MD5 for safety
            if (verticesAlreadyUsed.contains(hash)) {
                // discard this degenerate set and do NOT say we've used any of these vertices
                nWeak++;
                continue forcliques;
            }
        }

        // we haven't used any vertex in this degenerate set
        // now add all of these vertices
        // do NOT add before, or we'll add vertices we haven't used yet
        for (int v : set) {
            String hash = NetworkUtils.hash(v);
            verticesAlreadyUsed.add(hash);
        }
        finalDegenerateSets.add(set); // keep this degenerate set
    }

    logger.info("Job " + index + ": " + "Found " + finalDegenerateSets.size()
            + " strong nontrivial maximal degenerate sets found (" + nTrivial + " trivial and " + nWeak
            + " weak)");

    return finalDegenerateSets;
}

From source file:com.cloudfoundry.bae.cloudpush.Channel.java

/**
* genSign/*from   w w w .  j  ava 2s.  co  m*/
*
* ?
*
* ?method, url, ? ???
*/
private String genSign(String method, String url, Map<String, String> opt) {
    String gather = method + url;
    TreeMap<String, String> sortOpt = new TreeMap<String, String>(opt);
    NavigableSet<String> keySet = sortOpt.navigableKeySet();
    Iterator<String> it = keySet.iterator();
    while (it.hasNext()) {
        String key = it.next();
        String value = sortOpt.get(key);
        gather += key + "=" + value;
    }

    gather += secretKey;

    logger.info("sign source content: " + gather);

    String encodedGather;
    try {
        //            encodedGather = new URLCodec("utf8").encode(gather);
        encodedGather = URLEncoder.encode(gather, "utf8");
    } catch (UnsupportedEncodingException ex) {
        throw new ChannelException("wrong params are seted: " + gather, CHANNEL_SDK_PARAM);
    }
    String sign = DigestUtils.md5Hex(encodedGather);

    return sign;
}

From source file:org.cloudata.core.commitlog.ServerLocationManager.java

InetSocketAddress[] electCommitLogServers() throws IOException {
    if (numReplica > addrSet.size()) {
        throw new IOException(
                "Cannot elect commitlog server!! the num of available servers are " + addrSet.size());
    }/*  w ww. j  a v a 2s .  c  om*/

    InetSocketAddress target = new InetSocketAddress(InetAddress.getLocalHost(), pipePort);

    NavigableSet<InetSocketAddress> retSet = addrSet.tailSet(target, true);

    int index = 0;

    Iterator<InetSocketAddress> iter = retSet.iterator();
    InetSocketAddress[] ret = new InetSocketAddress[numReplica];

    while (iter.hasNext() && index < numReplica) {
        InetSocketAddress addr = iter.next();
        if (locationManager.hasDiskCapacity(addr)) {
            ret[index] = addr;
        }
    }

    if (index < numReplica) {
        Iterator<InetSocketAddress> headIter = addrSet.iterator();
        while (headIter.hasNext() && index < numReplica) {
            InetSocketAddress addr = headIter.next();
            if (locationManager.hasDiskCapacity(addr)) {
                ret[index++] = headIter.next();
            }
        }
    }

    if (ret.length < numReplica) {
        throw new IOException("Cannot elect commitlog server!! the num of elected servers are " + ret.length
                + ", check commitlog server's disk usage");
    }
    return ret;
}

From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java

private int getTolerance(Interval in, int minData, Function<TDoubleList, Integer> f) {
    final NavigableSet<Integer> times = in.getTails().keySet();
    if (times.size() <= 2) {
        return getToleranceFewSlots(in, minData);
    }/*from  w  w w .  ja  va  2 s  .c  o m*/
    final TDoubleList diffs = new TDoubleArrayList(times.size() - 1);
    final Iterator<Integer> it = times.iterator();
    if (it.hasNext()) {
        int prev = it.next().intValue();
        while (it.hasNext()) {
            final int curr = it.next().intValue();
            diffs.add(curr - prev - 1);
            prev = curr;
        }
    }
    return f.apply(diffs).intValue();
}